Skip to content

Commit

Permalink
Is that good enough memoization?
Browse files Browse the repository at this point in the history
  • Loading branch information
Edvard Makhlin committed May 8, 2024
1 parent 3d73c92 commit b07d337
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
35 changes: 21 additions & 14 deletions server/events/vcs/bitbucketcloud/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ func NewClient(httpClient *http.Client, username string, password string, atlant
}
}

var MY_UUID = ""

// GetModifiedFiles returns the names of files that were modified in the merge request
// relative to the repo root, e.g. parent/child/file.txt.
func (b *Client) GetModifiedFiles(logger logging.SimpleLogging, repo models.Repo, pull models.PullRequest) ([]string, error) {
Expand Down Expand Up @@ -165,25 +167,30 @@ func (b *Client) GetPullRequestComments(repo models.Repo, pullNum int) (comments
}

func (b *Client) GetMyUUID() (uuid string, err error) {
path := fmt.Sprintf("%s/2.0/user", b.BaseURL)
resp, err := b.makeRequest("GET", path, nil)
if MY_UUID == "" {
path := fmt.Sprintf("%s/2.0/user", b.BaseURL)
resp, err := b.makeRequest("GET", path, nil)

if err != nil {
return uuid, err
}
if err != nil {
return uuid, err
}

var user User
if err := json.Unmarshal(resp, &user); err != nil {
return uuid, errors.Wrapf(err, "Could not parse response %q", string(resp))
}
var user User
if err := json.Unmarshal(resp, &user); err != nil {
return uuid, errors.Wrapf(err, "Could not parse response %q", string(resp))
}

if err := validator.New().Struct(user); err != nil {
return uuid, errors.Wrapf(err, "API response %q was missing a field", string(resp))
}
if err := validator.New().Struct(user); err != nil {
return uuid, errors.Wrapf(err, "API response %q was missing a field", string(resp))
}

uuid = *user.UUID
return uuid, nil
uuid = *user.UUID
MY_UUID = uuid

return uuid, nil
} else {
return MY_UUID, nil
}
}

// PullIsApproved returns true if the merge request was approved.
Expand Down
1 change: 0 additions & 1 deletion server/events/vcs/bitbucketcloud/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,4 +514,3 @@ func TestClient_HidePRComments(t *testing.T) {
Ok(t, err)
Equals(t, 2, called)
}

0 comments on commit b07d337

Please sign in to comment.