Skip to content

Commit

Permalink
Prune old notifications (not replies or dms) after a certain amount a…
Browse files Browse the repository at this point in the history
…re read
  • Loading branch information
RedEnchilada committed Dec 20, 2014
1 parent 79679c5 commit d74a164
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion plugins/Notification/User_notification.php
Expand Up @@ -6,6 +6,8 @@

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

define('MAX_NOTIFICATIONS_PER_USER', 64);

class User_notification extends Memcached_DataObject
{
public $__table = 'user_notification'; // table name
Expand Down Expand Up @@ -79,7 +81,10 @@ function keyTypes()
static function getAllForUser($user) {
$notify = new User_notification();
$notify->user_id = $user->id;
if(!$notify->find())
$notify->orderBy('id ASC');

$noteCount = $notify->find();
if(!$noteCount)
return false;

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

// Prune "unimportant" (not replies or DMs) notes when we go over the limit
if ($noteCount > MAX_NOTIFICATIONS_PER_USER && !(
$notify->type == 'mention' || $notify->type == 'message'
)) {
$notify->delete();
$noteCount--;
continue;
}

$item['type'] = $notify->type;
$item['id'] = $notify->id;
$item['created'] = $notify->created;

$other = Profile::staticGet('id', $notify->from_user_id);
if($other == false) {
$notify->delete();
$noteCount--;
continue;
}
$item['user'] = array(
Expand All @@ -111,6 +126,7 @@ static function getAllForUser($user) {
if($notice == false) {
$item = null;
$notify->delete();
$noteCount--;
break;
}
$item['notice'] = array(
Expand All @@ -127,6 +143,7 @@ static function getAllForUser($user) {
if($notice == false) {
$item = null;
$notify->delete();
$noteCount--;
break;
}
$item['notice'] = array(
Expand All @@ -142,6 +159,7 @@ static function getAllForUser($user) {
if($group == false) {
$item = null;
$notify->delete();
$noteCount--;
break;
}
$item['group'] = array(
Expand Down

0 comments on commit d74a164

Please sign in to comment.