Skip to content

Commit 9bf9a40

Browse files
committed
replaced os.time() with ngx.time() for performance reasons
1 parent 05ef28d commit 9bf9a40

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/lua/api-gateway/validation/oauth2/oauthTokenValidator.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ function _M:getExpiresIn(expire_at)
7575
expire_at_s = expire_at / 1000
7676
end
7777

78-
local local_t = os.time()
78+
local local_t = ngx.time() -- os.time()
7979
local expires_in_s = expire_at_s - local_t
8080
return expires_in_s
8181
end
8282

8383
function _M:storeTokenInCache(cacheLookupKey, cachingObj, expire_at_ms_utc)
8484
local expires_in_s = self:getExpiresIn(expire_at_ms_utc)
8585
if ( expires_in_s <= 0 ) then
86-
ngx.log(ngx.DEBUG, "OAuth Token was not persisted in the cache as it has expired at:" .. tostring(expire_at_ms_utc) .. ", while now is:" .. tostring(os.time() * 1000) .. " ms.")
86+
ngx.log(ngx.DEBUG, "OAuth Token was not persisted in the cache as it has expired at:" .. tostring(expire_at_ms_utc) .. ", while now is:" .. tostring(ngx.time() * 1000) .. " ms.")
8787
return nil
8888
end
8989
local local_expire_in = math.min( expires_in_s, LOCAL_CACHE_TTL )

src/lua/api-gateway/validation/oauth2/userProfileValidator.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function _M:getExpiresIn(expire_at)
7373
expire_at_s = expire_at / 1000
7474
end
7575

76-
local local_t = os.time()
76+
local local_t = ngx.time() -- os.time()
7777
local expires_in_s = expire_at_s - local_t
7878
return expires_in_s
7979
end
@@ -108,7 +108,7 @@ function _M:storeProfileInCache(cacheLookupKey, cachingObj)
108108

109109
self:setKeyInLocalCache(cacheLookupKey, cachingObjString, localExpiresIn , "cachedUserProfiles")
110110
-- cache the use profile for 5 minutes
111-
self:setKeyInRedis(cacheLookupKey, "user_json", oauthTokenExpiration or ((os.time() + LOCAL_CACHE_TTL) * 1000 ), cachingObjString)
111+
self:setKeyInRedis(cacheLookupKey, "user_json", oauthTokenExpiration or ((ngx.time() + LOCAL_CACHE_TTL) * 1000 ), cachingObjString)
112112
end
113113

114114
--- Returns true if the profile is valid for the request context

0 commit comments

Comments
 (0)