6
6
7
7
require_once INSTALLDIR . '/classes/Memcached_DataObject.php ' ;
8
8
9
+ define ('MAX_NOTIFICATIONS_PER_USER ' , 64 );
10
+
9
11
class User_notification extends Memcached_DataObject
10
12
{
11
13
public $ __table = 'user_notification ' ; // table name
@@ -79,7 +81,10 @@ function keyTypes()
79
81
static function getAllForUser ($ user ) {
80
82
$ notify = new User_notification ();
81
83
$ notify ->user_id = $ user ->id ;
82
- if (!$ notify ->find ())
84
+ $ notify ->orderBy ('id ASC ' );
85
+
86
+ $ noteCount = $ notify ->find ();
87
+ if (!$ noteCount )
83
88
return false ;
84
89
85
90
$ return = array ();
@@ -88,13 +93,23 @@ static function getAllForUser($user) {
88
93
$ return [$ notify ->type ] = array ();
89
94
$ item = array ();
90
95
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
+
91
105
$ item ['type ' ] = $ notify ->type ;
92
106
$ item ['id ' ] = $ notify ->id ;
93
107
$ item ['created ' ] = $ notify ->created ;
94
108
95
109
$ other = Profile::staticGet ('id ' , $ notify ->from_user_id );
96
110
if ($ other == false ) {
97
111
$ notify ->delete ();
112
+ $ noteCount --;
98
113
continue ;
99
114
}
100
115
$ item ['user ' ] = array (
@@ -111,6 +126,7 @@ static function getAllForUser($user) {
111
126
if ($ notice == false ) {
112
127
$ item = null ;
113
128
$ notify ->delete ();
129
+ $ noteCount --;
114
130
break ;
115
131
}
116
132
$ item ['notice ' ] = array (
@@ -127,6 +143,7 @@ static function getAllForUser($user) {
127
143
if ($ notice == false ) {
128
144
$ item = null ;
129
145
$ notify ->delete ();
146
+ $ noteCount --;
130
147
break ;
131
148
}
132
149
$ item ['notice ' ] = array (
@@ -142,6 +159,7 @@ static function getAllForUser($user) {
142
159
if ($ group == false ) {
143
160
$ item = null ;
144
161
$ notify ->delete ();
162
+ $ noteCount --;
145
163
break ;
146
164
}
147
165
$ item ['group ' ] = array (
0 commit comments