Comparison

mod_mam/mod_mam.lua @ 2724:9f17d0f28d77

mod_mam: Don't ask the storage backend to count all items when expiry is disabled
author Kim Alvefur <zash@zash.se>
date Wed, 26 Apr 2017 11:46:22 +0200
parent 2711:ff1f7e61517f
child 2725:210c3a7644cb
comparison
equal deleted inserted replaced
2723:ec02ee02a04b 2724:9f17d0f28d77
53 end 53 end
54 module:log("debug", "See https://prosody.im/doc/storage and https://prosody.im/doc/archiving for more information"); 54 module:log("debug", "See https://prosody.im/doc/storage and https://prosody.im/doc/archiving for more information");
55 module:log("info", "Using in-memory fallback archive driver"); 55 module:log("info", "Using in-memory fallback archive driver");
56 archive = module:require "fallback_archive"; 56 archive = module:require "fallback_archive";
57 end 57 end
58
59 local use_total = true;
58 60
59 local cleanup; 61 local cleanup;
60 62
61 -- Handle prefs. 63 -- Handle prefs.
62 local function handle_prefs(event) 64 local function handle_prefs(event)
152 start = qstart; ["end"] = qend; -- Time range 154 start = qstart; ["end"] = qend; -- Time range
153 with = qwith; 155 with = qwith;
154 limit = qmax + 1; 156 limit = qmax + 1;
155 before = before; after = after; 157 before = before; after = after;
156 reverse = reverse; 158 reverse = reverse;
157 total = true; 159 total = get_total;
158 }); 160 });
159 161
160 if not data then 162 if not data then
161 origin.send(st.error_reply(stanza, "cancel", "internal-server-error", err)); 163 origin.send(st.error_reply(stanza, "cancel", "internal-server-error", err));
162 return true; 164 return true;
381 end 383 end
382 cleanup[user] = nil; 384 cleanup[user] = nil;
383 end 385 end
384 return math.random(cleanup_interval, cleanup_interval * 2); 386 return math.random(cleanup_interval, cleanup_interval * 2);
385 end); 387 end);
388 else
389 -- Don't ask the backend to count the potentially unbounded number of items,
390 -- it'll get slow.
391 use_total = false;
386 end 392 end
387 393
388 -- Stanzas sent by local clients 394 -- Stanzas sent by local clients
389 module:hook("pre-message/bare", c2s_message_handler, 0); 395 module:hook("pre-message/bare", c2s_message_handler, 0);
390 module:hook("pre-message/full", c2s_message_handler, 0); 396 module:hook("pre-message/full", c2s_message_handler, 0);