Software /
code /
prosody-modules
Diff
mod_http_oauth2/mod_http_oauth2.lua @ 4669:d3434fd151b5
mod_http_oauth2: Optimize cleanup timer
Pause exactly until after the next entry has expired.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 02 Sep 2021 23:03:41 +0200 |
parent | 4370:dee6b5098278 |
child | 4670:1b81b7269858 |
line wrap: on
line diff
--- a/mod_http_oauth2/mod_http_oauth2.lua Mon Aug 30 20:19:15 2021 +0200 +++ b/mod_http_oauth2/mod_http_oauth2.lua Thu Sep 02 23:03:41 2021 +0200 @@ -23,8 +23,12 @@ return "prosody:scope:default"; end +local function code_expires_in(code) + return os.difftime(os.time(), code.issued); +end + local function code_expired(code) - return os.difftime(os.time(), code.issued) > 120; + return code_expires_in(code) > 120; end local codes = cache.new(10000, function (_, code) @@ -37,7 +41,7 @@ codes:set(k, nil); k, code = codes:tail(); end - return 900; + return code and code_expires_in(code) + 1 or 900; end) local function oauth_error(err_name, err_desc)