mirror of
https://github.com/bjc/prosody.git
synced 2025-04-05 06:07:37 +03:00
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.
This commit is contained in:
parent
36bbf6b077
commit
0bb07b9711
1 changed files with 9 additions and 4 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue