Skip to content

Commit b178f8e

Browse files
Address AI feedback
Signed-off-by: Lukasz Gryglicki <[email protected]> Assisted by [OpenAI](https://platform.openai.com/) Assisted by [GitHub Copilot](https://github.com/features/copilot)
1 parent 63348fa commit b178f8e

File tree

8 files changed

+29
-15
lines changed

8 files changed

+29
-15
lines changed

cla-backend-go/github/github_repository.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,6 @@ func GetCoAuthorCommits(
838838
Authorized: false,
839839
}
840840
log.WithFields(f).Debugf("PR: %d, %+v", pr, summary)
841-
GithubUserCache.Set(cacheKey, user)
842841
} else {
843842
summary = &UserCommitSummary{
844843
SHA: utils.StringValue(commit.SHA),
@@ -852,7 +851,12 @@ func GetCoAuthorCommits(
852851
Authorized: false,
853852
}
854853
log.WithFields(f).Debugf("Co-author GitHub user details not found: %v", coAuthor)
855-
GithubUserCache.SetWithTTL(cacheKey, user, 30*time.Minute) // negative cache for 30 minutes
854+
}
855+
if found {
856+
GithubUserCache.Set(cacheKey, user)
857+
} else {
858+
// negative cache for 30 minutes (this is for GitHub user not found)
859+
GithubUserCache.SetWithTTL(cacheKey, user, 30*time.Minute)
856860
}
857861

858862
return summary, found

cla-backend-go/swagger/cla.v2.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4047,7 +4047,7 @@ paths:
40474047
- sign
40484048

40494049
/clear-cache:
4050-
get:
4050+
post:
40514051
summary: Clear cache
40524052
description: Clears the service cache
40534053
operationId: clearCaches

cla-backend-go/v2/sign/handlers.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,22 @@ func Configure(api *operations.EasyclaAPI, service Service, userService users.Se
8484
reqID := utils.GetRequestID(params.XREQUESTID)
8585
ctx := utils.ContextWithRequestAndUser(params.HTTPRequest.Context(), reqID, user) // nolint
8686
utils.SetAuthUserProperties(user, params.XUSERNAME, params.XEMAIL)
87+
f := logrus.Fields{
88+
"functionName": "v2.sign.handlers.ClearCachesHandler",
89+
utils.XREQUESTID: reqID,
90+
"authUserName": utils.StringValue(params.XUSERNAME),
91+
"authUserEmail": utils.StringValue(params.XEMAIL),
92+
}
93+
log.WithFields(f).Info("clearing caches")
8794
resp, err := service.ClearCaches(ctx)
8895
if err != nil {
96+
log.WithFields(f).WithError(err).Warn("failed to clear caches")
8997
if strings.Contains(err.Error(), "internal server error") {
9098
return sign.NewClearCachesInternalServerError().WithPayload(errorResponse(reqID, err))
9199
}
92100
return sign.NewClearCachesBadRequest().WithPayload(errorResponse(reqID, err))
93101
}
102+
log.WithFields(f).Info("caches cleared successfully")
94103
return sign.NewClearCachesOK().WithPayload(resp)
95104
})
96105

cla-backend-go/v2/sign/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ func (s *service) SignedIndividualCallbackGithub(ctx context.Context, payload []
616616
err = github.UpdateCacheAfterSignature(context.Background(), claUser, signature.ProjectID)
617617
if err != nil {
618618
log.WithFields(f).WithError(err).Warnf("unable to update cache for user: %s, project ID: %s", claUser.Username, signature.ProjectID)
619-
return err
619+
return nil
620620
}
621621

622622
} else {

cla-backend/cla/models/github_models.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
# GitHub usernames must be 3-39 characters long, can only contain alphanumeric characters or hyphens,
4242
# cannot begin or end with a hyphen, and cannot contain consecutive hyphens.
4343
GITHUB_USERNAME_REGEX = re.compile(r'^(?!-)(?!.*--)[A-Za-z0-9-]{3,39}(?<!-)$')
44-
NEGATIVE_CACHE_TTL = 180 # 3 minutes TTL for quick cache (all negative cases)
44+
NEGATIVE_CACHE_TTL = 180 # 3 minutes TTL for negative cache (all negative cases)
4545
PROJECT_CACHE_TTL = 10800 # 3 hours TTL for project cache (positive cases)
4646

4747
class TTLCache:
@@ -2517,7 +2517,8 @@ def get_co_author_commits(co_author, commit_sha, pr, installation_id) -> Tuple[U
25172517
if found:
25182518
github_user_cache.set(cache_key, user)
25192519
else:
2520-
github_user_cache.set_with_ttl(cache_key, user, 1800) # negative cache for 30 minutes
2520+
# negative cache for 30 minutes (this is for GitHub user not found)
2521+
github_user_cache.set_with_ttl(cache_key, user, 1800)
25212522
return (co_author_summary, found)
25222523

25232524

cla-backend/cla/routes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1879,10 +1879,10 @@ def user_from_token(auth_user: check_auth, request, response):
18791879
"""
18801880
return cla.controllers.user.get_or_create_user(auth_user).to_dict()
18811881

1882-
@hug.get("/clear-cache", versions=2)
1882+
@hug.post("/clear-cache", versions=2)
18831883
def clear_cache(auth_user: check_auth):
18841884
"""
1885-
GET: /clear-cache (v2)
1885+
POST: /clear-cache
18861886
18871887
Requires a valid Bearer token.
18881888
Clears in-memory caches used by the Python GitHub layer and returns

utils/clear_cache_go.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ API="${API_URL}/v4/clear-cache"
3232

3333
if [ ! -z "$DEBUG" ]
3434
then
35-
echo "curl -s -XGET -H \"X-ACL: ${XACL}\" -H \"Authorization: Bearer ${TOKEN}\" -H \"Content-Type: application/json\" \"${API}\""
36-
curl -s -XGET -H "X-ACL: ${XACL}" -H "Authorization: Bearer ${TOKEN}" -H "Content-Type: application/json" "${API}"
35+
echo "curl -s -XPOST -H \"X-ACL: ${XACL}\" -H \"Authorization: Bearer ${TOKEN}\" -H \"Content-Type: application/json\" \"${API}\""
36+
curl -s -XPOST -H "X-ACL: ${XACL}" -H "Authorization: Bearer ${TOKEN}" -H "Content-Type: application/json" "${API}"
3737
else
38-
curl -s -XGET -H "X-ACL: ${XACL}" -H "Authorization: Bearer ${TOKEN}" -H "Content-Type: application/json" "${API}" | jq -r '.'
38+
curl -s -XPOST -H "X-ACL: ${XACL}" -H "Authorization: Bearer ${TOKEN}" -H "Content-Type: application/json" "${API}" | jq -r '.'
3939
fi

utils/clear_cache_py.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Or to get a real user data:
55
# 2a) on local (non remote) computer: ~/get_oauth_token.sh (or ~/get_oauth_token_prod.sh) (will open browser, authenticate to LF, and return token data)
66
# 2b) edit 'cla/auth.py': uncomment: 'LG: for local environment override', then run server via: clear && AUTH0_USERNAME_CLAIM_CLI='http://lfx.dev/claims/username' yarn serve:ext
7-
# 2c) then TOKEN='value from the get_oauth_token.sh script' DEBUG='' ./utils/get_user_from_token_py.sh
7+
# 2c) then TOKEN='value from the get_oauth_token.sh script' DEBUG='' ./utils/clear_cache_py.sh
88

99
if [ -z "$TOKEN" ]
1010
then
@@ -38,8 +38,8 @@ API="${API_URL}/v2/clear-cache"
3838

3939
if [ ! -z "$DEBUG" ]
4040
then
41-
echo "curl -s -XGET -H \"X-ACL: ${XACL}\" -H \"Authorization: Bearer ${TOKEN}\" -H \"Content-Type: application/json\" \"${API}\""
42-
curl -s -XGET -H "X-ACL: ${XACL}" -H "Authorization: Bearer ${TOKEN}" -H "Content-Type: application/json" "${API}"
41+
echo "curl -s -XPOST -H \"X-ACL: ${XACL}\" -H \"Authorization: Bearer ${TOKEN}\" -H \"Content-Type: application/json\" \"${API}\""
42+
curl -s -XPOST -H "X-ACL: ${XACL}" -H "Authorization: Bearer ${TOKEN}" -H "Content-Type: application/json" "${API}"
4343
else
44-
curl -s -XGET -H "X-ACL: ${XACL}" -H "Authorization: Bearer ${TOKEN}" -H "Content-Type: application/json" "${API}" | jq -r '.'
44+
curl -s -XPOST -H "X-ACL: ${XACL}" -H "Authorization: Bearer ${TOKEN}" -H "Content-Type: application/json" "${API}" | jq -r '.'
4545
fi

0 commit comments

Comments
 (0)