Skip to content

Commit 3fc722e

Browse files
committed
clear cache
1 parent 2f26a4e commit 3fc722e

File tree

7 files changed

+871
-882
lines changed

7 files changed

+871
-882
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
ALTER TABLE api_key ADD COLUMN last_used_at bigint DEFAULT NULL;
1+
ALTER TABLE api_key ADD COLUMN last_used_at bigint DEFAULT 0;

migration/mysql/atlas.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
h1:3F5xjAgjZp5Vn131LnNB9/Hbz+eHAVqnv067kaFHy20=
1+
h1:jLGSNaAAAnRJ8v7ZLH7JHqjFe8HPv3wXCLetHRB/RXg=
22
20240626022133_initialization.sql h1:reSmqMhqnsrdIdPU2ezv/PXSL0COlRFX4gQA4U3/wMo=
33
20240708065726_update_audit_log_table.sql h1:fi8Xxw4WfSlHDyvq2Ni/8JUiZW8z/0qWWyWm6jFdUy8=
44
20240815043128_update_auto_ops_rule_table.sql h1:IKSW9W/XO6SWAYl5WPLJSg6KdsfcZ3rfQhIrf7aOnYc=
@@ -32,4 +32,4 @@ h1:3F5xjAgjZp5Vn131LnNB9/Hbz+eHAVqnv067kaFHy20=
3232
20250411093510_update_audit_log_table.sql h1:KDbGMLbeKhtUc833pAvKOiw9JdM4rXSUVc34TOywvc8=
3333
20250618071930_create_team_table.sql h1:Gc0+XyVk0zM+wWdWfqtkox2WQEnzftNX3FR7qpEAioU=
3434
20250711131250_update_indexes.sql h1:ghjrhD9mDtCHaHL7HbiAkTjmRHp6EZ3eerVjb8cSZCA=
35-
20251028072327_update_last_used_at_api_key_table.sql h1:2zpDE4qFt4WSN5mmMGlrzOSPcQRoVMzq4twSzABsn2I=
35+
20251028072327_update_last_used_at_api_key_table.sql h1:cuC7b8RV6QPv2LKij2Ld1cqkH8tpQB85Y+J8fHbi+38=

pkg/account/api/api_key.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -793,12 +793,15 @@ func (s *AccountService) UpdateAPIKeyLastUsedAt(
793793
}
794794

795795
err = s.mysqlClient.RunInTransactionV2(ctx, func(contextWithTx context.Context, _ mysql.Transaction) error {
796-
apiKey, err := s.accountStorage.GetAPIKey(contextWithTx, req.ApiKeyId, req.EnvironmentId)
796+
envAPIKey, err := s.accountStorage.GetEnvironmentAPIKey(contextWithTx, req.ApiKeyId)
797797
if err != nil {
798798
return err
799799
}
800+
apiKey := &domain.APIKey{
801+
APIKey: envAPIKey.ApiKey,
802+
}
800803
apiKey.UsedAt(req.LastUsedAt)
801-
return s.accountStorage.UpdateAPIKey(contextWithTx, apiKey, req.EnvironmentId)
804+
return s.accountStorage.UpdateAPIKey(contextWithTx, apiKey, envAPIKey.Environment.Id)
802805
})
803806
if err != nil {
804807
if errors.Is(err, v2as.ErrAPIKeyNotFound) {
@@ -815,7 +818,6 @@ func (s *AccountService) UpdateAPIKeyLastUsedAt(
815818
"Failed to update api key last used at",
816819
log.FieldsFromIncomingContext(ctx).AddFields(
817820
zap.Error(err),
818-
zap.String("environmentId", req.EnvironmentId),
819821
zap.String("id", req.ApiKeyId),
820822
)...,
821823
)

pkg/api/api/save_api_key_last_used_at.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,11 @@ func (s *grpcGatewayService) writeAPIKeyLastUsedAtCacheToDatabase(ctx context.Co
5252
}
5353

5454
func (s *grpcGatewayService) writeAPIKeyLastUsedAt(ctx context.Context) {
55+
keys := make([]string, 0)
5556
s.apiKeyLastUsedInfoCacher.Range(func(key, value interface{}) bool {
5657
apikey := key.(string)
5758
lastUsedAt := value.(int64)
59+
keys = append(keys, apikey)
5860
envAPIKey, err := s.getEnvironmentAPIKey(ctx, apikey)
5961
if err != nil {
6062
s.logger.Error("failed to get environment API key", zap.Error(err),
@@ -75,9 +77,8 @@ func (s *grpcGatewayService) writeAPIKeyLastUsedAt(ctx context.Context) {
7577
}
7678

7779
_, err = s.accountClient.UpdateAPIKeyLastUsedAt(ctx, &account.UpdateAPIKeyLastUsedAtRequest{
78-
EnvironmentId: envAPIKey.Environment.Id,
79-
ApiKeyId: envAPIKey.ApiKey.Id,
80-
LastUsedAt: lastUsedAt,
80+
ApiKeyId: envAPIKey.ApiKey.Id,
81+
LastUsedAt: lastUsedAt,
8182
})
8283
if err != nil {
8384
s.logger.Error("failed to update API key last used at", zap.Error(err),
@@ -87,4 +88,6 @@ func (s *grpcGatewayService) writeAPIKeyLastUsedAt(ctx context.Context) {
8788
}
8889
return true
8990
})
91+
92+
s.apiKeyLastUsedInfoCacher.Clear()
9093
}

proto/account/service.pb.go

Lines changed: 856 additions & 866 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proto/account/service.proto

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,7 @@ message UpdateAPIKeyResponse {}
343343

344344
message UpdateAPIKeyLastUsedAtRequest {
345345
string api_key_id = 1;
346-
string environment_id = 2;
347-
int64 last_used_at = 3;
346+
int64 last_used_at = 2;
348347
}
349348

350349
message UpdateAPIKeyLastUsedAtResponse {}

proto/proto.lock

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2099,11 +2099,6 @@
20992099
},
21002100
{
21012101
"id": 2,
2102-
"name": "environment_id",
2103-
"type": "string"
2104-
},
2105-
{
2106-
"id": 3,
21072102
"name": "last_used_at",
21082103
"type": "int64"
21092104
}

0 commit comments

Comments
 (0)