Notifications being incorrectly created for old posts

The issue seemed to get solved by itself (luckily) after a few days, but digging deeper helped me realize my initial SQL query was incomplete: the notifications.post_number field points to the first unread post in a given topic but every time a new post is created, its notification.created_at is updated to the new posts.created_at.

That explained some of the time discrepancies I was seeing, but not the uptick that mysteriously appeared and went away.

To fix the query, I’d have to first check post_timings to find the latest topic_id/post_number that the given user had seen, and use its created_at instead of the one coming from notifications.