Skip to content

Commit 42774a5

Browse files
author
Retro Bunny
committed
Merge pull request #311 from surevine/dwd/use-coalesce
Use COALESCE function for thread identifiers
2 parents 3bf77b8 + 7607290 commit 42774a5

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

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)