Software /
code /
prosody
Comparison
plugins/mod_storage_sql.lua @ 11970:f0e78fa8f24c
mod_storage_sql: Adjust handling of 'total' for multi-id queries
Otherwise a query for a set of ids may cause that value to be cached,
despite only covering a subset.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 30 Nov 2021 15:58:23 +0100 |
parent | 11969:395dce95508d |
child | 11971:0b350909da24 |
comparison
equal
deleted
inserted
replaced
11969:395dce95508d | 11970:f0e78fa8f24c |
---|---|
426 query = query or {}; | 426 query = query or {}; |
427 local user,store = username,self.store; | 427 local user,store = username,self.store; |
428 local cache_key = jid_join(username, host, self.store); | 428 local cache_key = jid_join(username, host, self.store); |
429 local total = archive_item_count_cache:get(cache_key); | 429 local total = archive_item_count_cache:get(cache_key); |
430 (total and item_count_cache_hit or item_count_cache_miss)(); | 430 (total and item_count_cache_hit or item_count_cache_miss)(); |
431 if total ~= nil and query.limit == 0 and query.start == nil and query.with == nil and query["end"] == nil and query.key == nil then | 431 if total ~= nil and query.limit == 0 and query.start == nil and query.with == nil and query["end"] == nil |
432 and query.key == nil and query.ids == nil then | |
432 return noop, total; | 433 return noop, total; |
433 end | 434 end |
434 local ok, result, err = engine:transaction(function() | 435 local ok, result, err = engine:transaction(function() |
435 local sql_query = [[ | 436 local sql_query = [[ |
436 SELECT "key", "type", "value", "when", "with" | 437 SELECT "key", "type", "value", "when", "with" |
450 if stats then | 451 if stats then |
451 for row in stats do | 452 for row in stats do |
452 total = row[1]; | 453 total = row[1]; |
453 end | 454 end |
454 end | 455 end |
455 if query.start == nil and query.with == nil and query["end"] == nil and query.key == nil then | 456 if query.start == nil and query.with == nil and query["end"] == nil and query.key == nil and query.ids == nil then |
456 archive_item_count_cache:set(cache_key, total); | 457 archive_item_count_cache:set(cache_key, total); |
457 end | 458 end |
458 if query.limit == 0 then -- Skip the real query | 459 if query.limit == 0 then -- Skip the real query |
459 return noop, total; | 460 return noop, total; |
460 end | 461 end |