Comparison

plugins/mod_storage_internal.lua @ 13346:53c347043cb5

mod_storage_internal: Clear archive item count cache after experimental trim The previous count would be invalid at this point. Should be possible to math out how many items are left, but this is left as future work.
author Kim Alvefur <zash@zash.se>
date Sun, 26 Nov 2023 18:02:13 +0100
parent 13344:958c759d3897
child 13402:6877786d73d7
comparison
equal deleted inserted replaced
13345:a74251a790ed 13346:53c347043cb5
346 function archive:users() 346 function archive:users()
347 return datamanager.users(host, self.store, "list"); 347 return datamanager.users(host, self.store, "list");
348 end 348 end
349 349
350 function archive:trim(username, to_when) 350 function archive:trim(username, to_when)
351 local cache_key = jid_join(username, host, self.store);
351 local list, err = datamanager.list_open(username, host, self.store); 352 local list, err = datamanager.list_open(username, host, self.store);
352 if not list then 353 if not list then
353 if err == nil then 354 if err == nil then
354 module:log("debug", "store already empty, can't trim"); 355 module:log("debug", "store already empty, can't trim");
355 return 0; 356 return 0;
376 end 377 end
377 -- TODO if exact then ... off by one? 378 -- TODO if exact then ... off by one?
378 if i == 1 then return 0; end 379 if i == 1 then return 0; end
379 local ok, err = datamanager.list_shift(username, host, self.store, i); 380 local ok, err = datamanager.list_shift(username, host, self.store, i);
380 if not ok then return ok, err; end 381 if not ok then return ok, err; end
382 archive_item_count_cache:set(cache_key, nil); -- TODO calculate how many items are left
381 return i-1; 383 return i-1;
382 end 384 end
383 385
384 function archive:delete(username, query) 386 function archive:delete(username, query)
385 local cache_key = jid_join(username, host, self.store); 387 local cache_key = jid_join(username, host, self.store);
386 if not query or next(query) == nil then 388 if not query or next(query) == nil then
387 archive_item_count_cache:set(cache_key, nil); 389 archive_item_count_cache:set(cache_key, nil); -- nil because we don't check if the following succeeds
388 return datamanager.list_store(username, host, self.store, nil); 390 return datamanager.list_store(username, host, self.store, nil);
389 end 391 end
390 392
391 if use_shift and next(query) == "end" and next(query, "end") == nil then 393 if use_shift and next(query) == "end" and next(query, "end") == nil then
392 return self:trim(username, query["end"]); 394 return self:trim(username, query["end"]);