ssb: Only re-populate the messages_stats table on first creation.
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 21m38s
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 21m38s
This commit is contained in:
parent
c728e05032
commit
82e876a892
17
src/ssb.db.c
17
src/ssb.db.c
@ -108,12 +108,16 @@ void tf_ssb_db_init(tf_ssb_t* ssb)
|
||||
" flags INTEGER,"
|
||||
" UNIQUE(author, sequence)"
|
||||
")");
|
||||
_tf_ssb_db_exec(db,
|
||||
"CREATE TABLE IF NOT EXISTS messages_stats ("
|
||||
" author TEXT PRIMARY KEY,"
|
||||
" max_sequence INTEGER,"
|
||||
" max_timestamp READ"
|
||||
")");
|
||||
if (!_tf_ssb_db_has_rows(db, "PRAGMA table_list('messages_stats')"))
|
||||
{
|
||||
_tf_ssb_db_exec(db,
|
||||
"CREATE TABLE IF NOT EXISTS messages_stats ("
|
||||
" author TEXT PRIMARY KEY,"
|
||||
" max_sequence INTEGER,"
|
||||
" max_timestamp READ"
|
||||
")");
|
||||
_tf_ssb_db_exec(db, "INSERT OR REPLACE INTO messages_stats (author, max_sequence, max_timestamp) SELECT author, MAX(sequence), MAX(timestamp) FROM messages GROUP BY author");
|
||||
}
|
||||
_tf_ssb_db_exec(db,
|
||||
"CREATE TRIGGER IF NOT EXISTS messages_ai_stats AFTER INSERT ON messages BEGIN INSERT INTO messages_stats(author, max_sequence, max_timestamp) VALUES (new.author, "
|
||||
"new.sequence, new.timestamp) ON CONFLICT DO UPDATE SET max_sequence = MAX(max_sequence, excluded.max_sequence), max_timestamp = MAX(max_timestamp, "
|
||||
@ -121,7 +125,6 @@ void tf_ssb_db_init(tf_ssb_t* ssb)
|
||||
_tf_ssb_db_exec(db,
|
||||
"CREATE TRIGGER IF NOT EXISTS messages_ad_stats AFTER DELETE ON messages BEGIN UPDATE messages_stats SET max_sequence = (SELECT MAX(messages.sequence) FROM messages WHERE "
|
||||
"messages.author = old.author), max_timestamp = (SELECT MAX(messages.timestamp) FROM messages WHERE messages.author = old.author); END");
|
||||
_tf_ssb_db_exec(db, "INSERT OR REPLACE INTO messages_stats (author, max_sequence, max_timestamp) SELECT author, MAX(sequence), MAX(timestamp) FROM messages GROUP BY author");
|
||||
|
||||
if (_tf_ssb_db_has_rows(db, "SELECT name FROM pragma_table_info('messages') WHERE name = 'content' AND type == 'TEXT'"))
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user