aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2021-11-30 16:26:01 +0100
committerKim Alvefur <zash@zash.se>2021-11-30 16:26:01 +0100
commit0bb07b9711102edc0ff7eb9ddfe5014f2d7b8594 (patch)
tree9e8181f5d8350ec0a627b8b2eb4fe46191697110
parent36bbf6b07704941852cb894c2936ced1aa44baf5 (diff)
downloadprosody-0bb07b9711102edc0ff7eb9ddfe5014f2d7b8594.tar.gz
prosody-0bb07b9711102edc0ff7eb9ddfe5014f2d7b8594.zip
mod_storage_sql: Return cached total where it makes sense
This should skip the summary SQL query when not needed, ie when the cached value can be used directly.
-rw-r--r--plugins/mod_storage_sql.lua13
1 files changed, 9 insertions, 4 deletions
diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua
index 7babd969..3bfe1739 100644
--- a/plugins/mod_storage_sql.lua
+++ b/plugins/mod_storage_sql.lua
@@ -428,9 +428,13 @@ function archive_store:find(username, query)
local cache_key = jid_join(username, host, self.store);
local total = archive_item_count_cache:get(cache_key);
(total and item_count_cache_hit or item_count_cache_miss)();
- if total ~= nil and query.limit == 0 and query.start == nil and query.with == nil and query["end"] == nil
- and query.key == nil and query.ids == nil then
- return noop, total;
+ if query.start == nil and query.with == nil and query["end"] == nil and query.key == nil and query.ids == nil then
+ -- the query is for the whole archive, so a cached 'total' should be a
+ -- relatively accurate response if that's all that is requested
+ if total ~= nil and query.limit == 0 then return noop, total; end
+ else
+ -- not usable, so refresh it later if needed
+ total = nil;
end
local ok, result, err = engine:transaction(function()
local sql_query = [[
@@ -445,7 +449,8 @@ function archive_store:find(username, query)
archive_where(query, args, where);
-- Total matching
- if query.total then
+ if query.total and not total then
+
local stats = engine:select("SELECT COUNT(*) FROM \"prosodyarchive\" WHERE "
.. t_concat(where, " AND "), unpack(args));
if stats then