croque-scp / notifier

Forum notification service for Wikidot
http://notifications.wikidot.com
MIT License
13 stars 6 forks source link

Fetch notifiable user list before iterating users #58

Closed rossjrw closed 1 year ago

rossjrw commented 1 year ago

Currently, the notifier filters users by the selected channel and then iterates one-by-one to notify all of them.

However, on any given run, the vast majority of users do not have any notifications waiting for them. Iterating them one-by-one, in this case, is exceptionally stupid.

Instead, the database should first be asked for a list of users that have notifications waiting for them. Only this list of users should then be iterated.


Requirements:


Counterpoint: this might not be possible, because the bottom bounding timestamp for the post search for each user varies between users - it's the timestamp at which they were last notified. There's not a catch-all query that could answer this question for all users regardless of timestamp.

Countercounterpoint: a given user's last notification timestamp is recorded in the database, and I can just use that. This will possibly need a subquery to retrieve that data for immediate use, and that'll be real slow, but I don't care, because it's competing against running main query 400 times in a row and that's not a very high bar.


Manual subscriptions are going to be difficult.

I don't need to worry about manual unsubscriptions, because it doesn't matter if there are some users in the resulting list who shouldn't be. I do need to worry about manual subscriptions, because the list must contain everyone that it needs to.