diff options
author | Yorhel <git@yorhel.nl> | 2015-10-12 20:58:02 +0200 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2015-10-12 21:17:48 +0200 |
commit | 61251790bd1da10eebee3c56a70a9711e7680ce8 (patch) | |
tree | ccf47fd384b54cf4d5c9bc378c556fc3aa3e6535 /lib | |
parent | 1a6dd0160a75bc83390912dfb2635cd5664ce9ee (diff) |
Notifications: Allow max 500 notifies per user + add SQL index on uid
Turns out that fetching whether or not you have unread notifications
(done on every pageview if you're logged in) was pretty slow. The index
speeds up both that query and the "my notifications" view.
The extra purge for old notifications for users with more than 500
notifications ensures that the index stays effective for the unread
notifications count. Otherwise it'll have to read half of the
notifications table anyway to check the 'unread' filter.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Multi/Maintenance.pm | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/lib/Multi/Maintenance.pm b/lib/Multi/Maintenance.pm index 23fb6db5..23e17fff 100644 --- a/lib/Multi/Maintenance.pm +++ b/lib/Multi/Maintenance.pm @@ -93,6 +93,8 @@ my %dailies = ( cleansessions => q|DELETE FROM sessions WHERE lastused < NOW()-'1 month'::interval|, cleannotifications => q|DELETE FROM notifications WHERE read < NOW()-'1 month'::interval|, + cleannotifications2=> q|DELETE FROM notifications WHERE id IN ( + SELECT id FROM (SELECT id, row_number() OVER (PARTITION BY uid ORDER BY id DESC) > 500 from notifications) AS x(id,del) WHERE x.del)|, rmunconfirmusers => q|DELETE FROM users WHERE registered < NOW()-'1 week'::interval AND NOT email_confirmed|, cleanthrottle => q|DELETE FROM login_throttle WHERE timeout < NOW()|, ); |