Skip to content

Commit 0f1472f

Browse files
author
Edvard Makhlin
committed
Is that good enough memoization?
1 parent 3d73c92 commit 0f1472f

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

server/events/vcs/bitbucketcloud/client.go

+21-14
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ func NewClient(httpClient *http.Client, username string, password string, atlant
4040
}
4141
}
4242

43+
var MY_UUID = ""
44+
4345
// GetModifiedFiles returns the names of files that were modified in the merge request
4446
// relative to the repo root, e.g. parent/child/file.txt.
4547
func (b *Client) GetModifiedFiles(logger logging.SimpleLogging, repo models.Repo, pull models.PullRequest) ([]string, error) {
@@ -165,25 +167,30 @@ func (b *Client) GetPullRequestComments(repo models.Repo, pullNum int) (comments
165167
}
166168

167169
func (b *Client) GetMyUUID() (uuid string, err error) {
168-
path := fmt.Sprintf("%s/2.0/user", b.BaseURL)
169-
resp, err := b.makeRequest("GET", path, nil)
170+
if MY_UUID == "" {
171+
path := fmt.Sprintf("%s/2.0/user", b.BaseURL)
172+
resp, err := b.makeRequest("GET", path, nil)
170173

171-
if err != nil {
172-
return uuid, err
173-
}
174+
if err != nil {
175+
return uuid, err
176+
}
174177

175-
var user User
176-
if err := json.Unmarshal(resp, &user); err != nil {
177-
return uuid, errors.Wrapf(err, "Could not parse response %q", string(resp))
178-
}
178+
var user User
179+
if err := json.Unmarshal(resp, &user); err != nil {
180+
return uuid, errors.Wrapf(err, "Could not parse response %q", string(resp))
181+
}
179182

180-
if err := validator.New().Struct(user); err != nil {
181-
return uuid, errors.Wrapf(err, "API response %q was missing a field", string(resp))
182-
}
183+
if err := validator.New().Struct(user); err != nil {
184+
return uuid, errors.Wrapf(err, "API response %q was missing a field", string(resp))
185+
}
183186

184-
uuid = *user.UUID
185-
return uuid, nil
187+
uuid = *user.UUID
188+
MY_UUID = uuid
186189

190+
return uuid, nil
191+
} else {
192+
return MY_UUID, nil
193+
}
187194
}
188195

189196
// PullIsApproved returns true if the merge request was approved.

0 commit comments

Comments
 (0)