From f0211f621e67ec3c8e67a243f566893972109141 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Wed, 19 Mar 2025 19:09:29 -0400 Subject: [PATCH] ssb: That's just a weird formulation of this query. I saw it in a profile. --- src/ssb.db.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ssb.db.c b/src/ssb.db.c index 7841c544..0d4d3375 100644 --- a/src/ssb.db.c +++ b/src/ssb.db.c @@ -981,7 +981,7 @@ bool tf_ssb_db_get_latest_message_by_author(tf_ssb_t* ssb, const char* author, i bool found = false; sqlite3_stmt* statement; sqlite3* db = tf_ssb_acquire_db_reader(ssb); - const char* query = "SELECT id, sequence FROM messages WHERE author = ?1 AND sequence = (SELECT MAX(sequence) FROM messages WHERE author = ?1)"; + const char* query = "SELECT id, sequence FROM messages WHERE author = ?1 ORDER BY sequence DESC LIMIT 1"; if (sqlite3_prepare(db, query, -1, &statement, NULL) == SQLITE_OK) { if (sqlite3_bind_text(statement, 1, author, -1, NULL) == SQLITE_OK && sqlite3_step(statement) == SQLITE_ROW)