Software /
code /
prosody-modules
Comparison
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 |
comparison
equal
deleted
inserted
replaced
4668:ede9682c2022 | 4669:d3434fd151b5 |
---|---|
21 return "prosody:scope:admin"; | 21 return "prosody:scope:admin"; |
22 end | 22 end |
23 return "prosody:scope:default"; | 23 return "prosody:scope:default"; |
24 end | 24 end |
25 | 25 |
26 local function code_expires_in(code) | |
27 return os.difftime(os.time(), code.issued); | |
28 end | |
29 | |
26 local function code_expired(code) | 30 local function code_expired(code) |
27 return os.difftime(os.time(), code.issued) > 120; | 31 return code_expires_in(code) > 120; |
28 end | 32 end |
29 | 33 |
30 local codes = cache.new(10000, function (_, code) | 34 local codes = cache.new(10000, function (_, code) |
31 return code_expired(code) | 35 return code_expired(code) |
32 end); | 36 end); |
35 local k, code = codes:tail(); | 39 local k, code = codes:tail(); |
36 while code and code_expired(code) do | 40 while code and code_expired(code) do |
37 codes:set(k, nil); | 41 codes:set(k, nil); |
38 k, code = codes:tail(); | 42 k, code = codes:tail(); |
39 end | 43 end |
40 return 900; | 44 return code and code_expires_in(code) + 1 or 900; |
41 end) | 45 end) |
42 | 46 |
43 local function oauth_error(err_name, err_desc) | 47 local function oauth_error(err_name, err_desc) |
44 return errors.new({ | 48 return errors.new({ |
45 type = "modify"; | 49 type = "modify"; |