Skip to content

Commit

Permalink
Delete posts that share a timestamp with a user
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rossjrw committed May 4, 2024
1 parent 2a85c2c commit 7fe5885
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion notifier/database/queries/delete_non_notifiable_posts.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7fe5885

Please sign in to comment.