Skip to content

Commit

Permalink
Merge pull request #311 from surevine/dwd/use-coalesce
Browse files Browse the repository at this point in the history
Use COALESCE function for thread identifiers
  • Loading branch information
Retro Bunny committed Aug 12, 2015
2 parents 3bf77b8 + 7607290 commit 42774a5
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,9 @@ public class Sql92NodeStoreDialect implements NodeStoreSQLDialect {

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

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

0 comments on commit 42774a5

Please sign in to comment.