@@ -30,9 +30,8 @@ func (s *grpcGatewayService) cacheAPIKeyLastUsedAt(
3030	if  cache , ok  :=  s .apiKeyLastUsedInfoCacher .Load (apiKey .Id ); ok  {
3131		lastUsedAtCache  :=  cache .(int64 )
3232		if  lastUsedAtCache  <  lastUsedAt  {
33- 			lastUsedAtCache   =   lastUsedAt 
33+ 			s . apiKeyLastUsedInfoCacher . Store ( apiKey . Id ,  lastUsedAt ) 
3434		}
35- 		s .apiKeyLastUsedInfoCacher .Store (apiKey .Id , lastUsedAtCache )
3635		return 
3736	}
3837	s .apiKeyLastUsedInfoCacher .Store (apiKey .Id , lastUsedAt )
@@ -52,37 +51,18 @@ func (s *grpcGatewayService) writeAPIKeyLastUsedAtCacheToDatabase(ctx context.Co
5251}
5352
5453func  (s  * grpcGatewayService ) writeAPIKeyLastUsedAt (ctx  context.Context ) {
55- 	keys  :=  make ([]string , 0 )
5654	s .apiKeyLastUsedInfoCacher .Range (func (key , value  interface {}) bool  {
57- 		apikey  :=  key .(string )
55+ 		apiKey  :=  key .(string )
5856		lastUsedAt  :=  value .(int64 )
59- 		keys  =  append (keys , apikey )
60- 		envAPIKey , err  :=  s .getEnvironmentAPIKey (ctx , apikey )
61- 		if  err  !=  nil  {
62- 			s .logger .Error ("failed to get environment API key" , zap .Error (err ),
63- 				zap .String ("apiKeyId" , apikey ),
64- 			)
65- 			return  true 
66- 		}
67- 
68- 		if  envAPIKey  ==  nil  {
69- 			s .logger .Error ("environment API key not found" ,
70- 				zap .String ("apiKeyId" , apikey ),
71- 			)
72- 			return  true 
73- 		}
74- 
75- 		if  envAPIKey .ApiKey .LastUsedAt  >=  lastUsedAt  {
76- 			return  true 
77- 		}
7857
79- 		_ , err  =  s .accountClient .UpdateAPIKeyLastUsedAt (ctx , & account.UpdateAPIKeyLastUsedAtRequest {
80- 			ApiKeyId :   envAPIKey . ApiKey . Id ,
58+ 		_ , err  : =s .accountClient .UpdateAPIKeyLastUsedAt (ctx , & account.UpdateAPIKeyLastUsedAtRequest {
59+ 			ApiKeyId :   apiKey ,
8160			LastUsedAt : lastUsedAt ,
8261		})
8362		if  err  !=  nil  {
8463			s .logger .Error ("failed to update API key last used at" , zap .Error (err ),
85- 				zap .String ("apiKeyId" , apikey ),
64+ 				zap .String ("apiKeyId" , apiKey ),
65+ 				zap .Int64 ("lastUsedAt" , lastUsedAt ),
8666			)
8767			return  true 
8868		}
0 commit comments