# HG changeset patch # User Kim Alvefur # Date 1630616621 -7200 # Node ID d3434fd151b5c7b9f8e5271a981dd48ae2445522 # Parent ede9682c20228d2d8d81160c4ac926a8a38d087e mod_http_oauth2: Optimize cleanup timer Pause exactly until after the next entry has expired. diff -r ede9682c2022 -r d3434fd151b5 mod_http_oauth2/mod_http_oauth2.lua --- 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)