Deduplicate threads on Newest forum tab #38
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "deduplicate-forum-newest"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This is some work-in-progress code to try and make the Newest tab on the forum nicer when we have a popular forum thread that's getting tons of responses, so that the spam doesn't dominate a whole page of results.
The original query simply selects ALL forum comments ordered by created at:
In order to de-duplicate by thread, I could add a
SELECT DISTINCT ON (threads.id)
to ensure that each thread ID is only returned once. However, when doing a DISTINCT ON you are required to ORDER BY the same field. But ordering by thread ID is not useful for the "Newest" tab when what I need to order by is the timestamp of the recent comment.I found some info on StackOverflow here and here how you can ORDER BY a different column than you SELECT DISTINCT ON. I'm currently trying the subquery approach.
The raw SQL query I'm trying to build looks so far like this (annotated):
WIP: Deduplicate threads on Newest forum tabto Deduplicate threads on Newest forum tab