Skip to content

Commit 7607290

Browse files
author
Dave Cridland
committed
Use COALESCE function for thread identifiers
This is an exact replacement, but in the WHERE clause this saves around 75% of the execution time, making post retrieval via RSM considerably faster.
1 parent 3bf77b8 commit 7607290

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/main/java/org/buddycloud/channelserver/db/jdbc/dialect/Sql92NodeStoreDialect.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,9 @@ public class Sql92NodeStoreDialect implements NodeStoreSQLDialect {
238238

239239
private static final String SELECT_NODE_THREADS = "SELECT \"node\", \"id\", \"updated\", \"xml\", \"in_reply_to\", "
240240
+ "\"thread_id\", \"thread_updated\", \"created\" FROM \"items\"," + "(SELECT MAX(\"updated\") AS \"thread_updated\", \"thread_id\" FROM "
241-
+ "(SELECT \"updated\", " + "(CASE WHEN (\"in_reply_to\" IS NULL) THEN \"id\" ELSE \"in_reply_to\" END) AS \"thread_id\" "
241+
+ "(SELECT \"updated\", COALESCE(\"in_reply_to\",\"id\") AS \"thread_id\" "
242242
+ "FROM \"items\" WHERE \"node\" = ?) AS \"_items\" " + "GROUP BY \"thread_id\" " + "HAVING MAX(\"updated\") < ? "
243-
+ "ORDER BY \"thread_updated\" DESC LIMIT ?) AS \"threads\" " + "WHERE \"in_reply_to\" = \"thread_id\" OR \"id\" = \"thread_id\" "
243+
+ "ORDER BY \"thread_updated\" DESC LIMIT ?) AS \"threads\" " + "WHERE COALESCE(\"in_reply_to\", \"id\") = \"thread_id\" "
244244
+ "ORDER BY \"thread_updated\" DESC, \"updated\"";
245245

246246
private static final String COUNT_NODE_THREADS = "SELECT COUNT(DISTINCT \"thread_id\") "

0 commit comments

Comments
 (0)