Software /
code /
prosody
Comparison
plugins/mod_storage_sql.lua @ 10222:51f145094648
mod_storage_*: Also include timestmap of first message in :summary API
For completeness along with most recent timestamp. Might be nice to be
able to order by oldest unread message.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 23 Aug 2019 01:15:44 +0200 |
parent | 10221:068692cb9e78 |
child | 10564:3098eac31139 |
comparison
equal
deleted
inserted
replaced
10221:068692cb9e78 | 10222:51f145094648 |
---|---|
422 function archive_store:summary(username, query) | 422 function archive_store:summary(username, query) |
423 query = query or {}; | 423 query = query or {}; |
424 local user,store = username,self.store; | 424 local user,store = username,self.store; |
425 local ok, result = engine:transaction(function() | 425 local ok, result = engine:transaction(function() |
426 local sql_query = [[ | 426 local sql_query = [[ |
427 SELECT DISTINCT "with", COUNT(*), MAX("when") | 427 SELECT DISTINCT "with", COUNT(*), MIN("when"), MAX("when") |
428 FROM "prosodyarchive" | 428 FROM "prosodyarchive" |
429 WHERE %s | 429 WHERE %s |
430 GROUP BY "with" | 430 GROUP BY "with" |
431 ORDER BY "sort_id" %s%s; | 431 ORDER BY "sort_id" %s%s; |
432 ]]; | 432 ]]; |
445 and "DESC" or "ASC", query.limit and " LIMIT ?" or ""); | 445 and "DESC" or "ASC", query.limit and " LIMIT ?" or ""); |
446 return engine:select(sql_query, unpack(args)); | 446 return engine:select(sql_query, unpack(args)); |
447 end); | 447 end); |
448 if not ok then return ok, result end | 448 if not ok then return ok, result end |
449 local counts = {}; | 449 local counts = {}; |
450 local latest = {}; | 450 local earliest, latest = {}, {}; |
451 for row in result do | 451 for row in result do |
452 local with, count = row[1], row[2]; | 452 local with, count = row[1], row[2]; |
453 counts[with] = count; | 453 counts[with] = count; |
454 latest[with] = row[3]; | 454 earliest[with] = row[3]; |
455 latest[with] = row[4]; | |
455 end | 456 end |
456 return { | 457 return { |
457 counts = counts; | 458 counts = counts; |
459 earliest = earliest; | |
458 latest = latest; | 460 latest = latest; |
459 }; | 461 }; |
460 end | 462 end |
461 | 463 |
462 function archive_store:delete(username, query) | 464 function archive_store:delete(username, query) |