Sunday, 15 April 2012

php - How to handle user notifications for same object? -



php - How to handle user notifications for same object? -

i'm using code http://codegains.com/2014/06/laravel-4-notification-system/ notification system, works ok. i've run problems, users flooded notifications. mean is, if 5 users likes 1 image, author of image 5 notifications "user x liked image image.png". x 5 different name. want know if has thought on how alter in above case, user 1 notification saying "users x,y,z liked image image.png" .

edit: here's construction of tables "notifications"

now i'm trying grouping notifications iterating through notifications selected db order object_id , compare current object_id previous , right form. takes way much time, because starts on every page load (main page). , 1000 users, 1000 notifications... :\

try grouping created_at.

you check created_at within 30 seconds , grouping results , fire every notification above 30 seconds , otherwise grouping , fire group.

for example:

$onotifications = notifications::where('is_read', '=', false)->get(); $anotifygroup = []; foreach($onotifications $onotify) { if($onotify->created_at->diffinseconds(carbon::now()) <= 30) { // add together grouping later fire $anotifiygroup[] = $onotify; } else { //fire notification } } //fire grouped notification foreach($anotifygroup $onotify) { //fire }

php laravel notifications

No comments:

Post a Comment