Skip to content

Commit d74a164

Browse files
author
RedEnchilada
committed
Prune old notifications (not replies or dms) after a certain amount are read
1 parent 79679c5 commit d74a164

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

plugins/Notification/User_notification.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
88

9+
define('MAX_NOTIFICATIONS_PER_USER', 64);
10+
911
class User_notification extends Memcached_DataObject
1012
{
1113
public $__table = 'user_notification'; // table name
@@ -79,7 +81,10 @@ function keyTypes()
7981
static function getAllForUser($user) {
8082
$notify = new User_notification();
8183
$notify->user_id = $user->id;
82-
if(!$notify->find())
84+
$notify->orderBy('id ASC');
85+
86+
$noteCount = $notify->find();
87+
if(!$noteCount)
8388
return false;
8489

8590
$return = array();
@@ -88,13 +93,23 @@ static function getAllForUser($user) {
8893
$return[$notify->type] = array();
8994
$item = array();
9095

96+
// Prune "unimportant" (not replies or DMs) notes when we go over the limit
97+
if ($noteCount > MAX_NOTIFICATIONS_PER_USER && !(
98+
$notify->type == 'mention' || $notify->type == 'message'
99+
)) {
100+
$notify->delete();
101+
$noteCount--;
102+
continue;
103+
}
104+
91105
$item['type'] = $notify->type;
92106
$item['id'] = $notify->id;
93107
$item['created'] = $notify->created;
94108

95109
$other = Profile::staticGet('id', $notify->from_user_id);
96110
if($other == false) {
97111
$notify->delete();
112+
$noteCount--;
98113
continue;
99114
}
100115
$item['user'] = array(
@@ -111,6 +126,7 @@ static function getAllForUser($user) {
111126
if($notice == false) {
112127
$item = null;
113128
$notify->delete();
129+
$noteCount--;
114130
break;
115131
}
116132
$item['notice'] = array(
@@ -127,6 +143,7 @@ static function getAllForUser($user) {
127143
if($notice == false) {
128144
$item = null;
129145
$notify->delete();
146+
$noteCount--;
130147
break;
131148
}
132149
$item['notice'] = array(
@@ -142,6 +159,7 @@ static function getAllForUser($user) {
142159
if($group == false) {
143160
$item = null;
144161
$notify->delete();
162+
$noteCount--;
145163
break;
146164
}
147165
$item['group'] = array(

0 commit comments

Comments
 (0)