From 7fe588561b94727fc47fe97aa5b1cde7e0efad5b Mon Sep 17 00:00:00 2001 From: Ross Williams Date: Sat, 4 May 2024 13:57:17 +0100 Subject: [PATCH] Delete posts that share a timestamp with a user When a user is notified about a post, their last notified timestamp is set to the timestamp of the most recent post they were notified about. Before this commit, a post was only deleted when a user's timestamp is greater than its. Because a user's timestamp will necessarily be equal to that of at least one post in the database, this causes one post per user to be erroneously kept when it should be deleted. Deleting posts where a user shares its timestamp fixes this, and is safe to do because we can guarantee the user has already been notified about it. The only time that might not be true is if two posts are made during the same second (already unlikely) _and_ Wikidot refreshes the RSS feed between the two, including one but not the other. I consider this impossible. This is an O(n) problem, because there can be at most one post per user that falls afoul of this, but hey whatever --- notifier/database/queries/delete_non_notifiable_posts.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notifier/database/queries/delete_non_notifiable_posts.sql b/notifier/database/queries/delete_non_notifiable_posts.sql index a2d1283..fb04476 100644 --- a/notifier/database/queries/delete_non_notifiable_posts.sql +++ b/notifier/database/queries/delete_non_notifiable_posts.sql @@ -46,7 +46,7 @@ WHERE AND user_config.user_id <> notifiable_post.author_user_id -- Users whose last notified post was earlier than this one - AND user_config.notified_timestamp <= notifiable_post.posted_timestamp + AND user_config.notified_timestamp < notifiable_post.posted_timestamp -- Filter out users unsubscribed to this post AND (thread_sub.sub IS NULL OR thread_sub.sub = 1)