Comparison

plugins/mod_mam/mod_mam.lua @ 8132:6ddddfe05a74

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 8047:eb9784561387
child 8137:484ea6201c6c
comparison
equal deleted inserted replaced
8131:c8e3a0caa0a9 8132:6ddddfe05a74
49 end 49 end
50 module:log("debug", "See https://prosody.im/doc/storage and https://prosody.im/doc/archiving for more information"); 50 module:log("debug", "See https://prosody.im/doc/storage and https://prosody.im/doc/archiving for more information");
51 module:log("info", "Using in-memory fallback archive driver"); 51 module:log("info", "Using in-memory fallback archive driver");
52 archive = module:require "fallback_archive"; 52 archive = module:require "fallback_archive";
53 end 53 end
54
55 local use_total = true;
54 56
55 local cleanup; 57 local cleanup;
56 58
57 -- Handle prefs. 59 -- Handle prefs.
58 module:hook("iq/self/"..xmlns_mam..":prefs", function(event) 60 module:hook("iq/self/"..xmlns_mam..":prefs", function(event)
135 start = qstart; ["end"] = qend; -- Time range 137 start = qstart; ["end"] = qend; -- Time range
136 with = qwith; 138 with = qwith;
137 limit = qmax + 1; 139 limit = qmax + 1;
138 before = before; after = after; 140 before = before; after = after;
139 reverse = reverse; 141 reverse = reverse;
140 total = true; 142 total = get_total;
141 }); 143 });
142 144
143 if not data then 145 if not data then
144 origin.send(st.error_reply(stanza, "cancel", "internal-server-error", err)); 146 origin.send(st.error_reply(stanza, "cancel", "internal-server-error", err));
145 return true; 147 return true;
357 end 359 end
358 cleanup[user] = nil; 360 cleanup[user] = nil;
359 end 361 end
360 return math.random(cleanup_interval, cleanup_interval * 2); 362 return math.random(cleanup_interval, cleanup_interval * 2);
361 end); 363 end);
364 else
365 -- Don't ask the backend to count the potentially unbounded number of items,
366 -- it'll get slow.
367 use_total = false;
362 end 368 end
363 369
364 -- Stanzas sent by local clients 370 -- Stanzas sent by local clients
365 module:hook("pre-message/bare", c2s_message_handler, 0); 371 module:hook("pre-message/bare", c2s_message_handler, 0);
366 module:hook("pre-message/full", c2s_message_handler, 0); 372 module:hook("pre-message/full", c2s_message_handler, 0);