From 343025decefee03eb88231c91c95a663f9f01063 Mon Sep 17 00:00:00 2001 From: ralf Date: Tue, 9 Jul 2024 16:16:33 +0200 Subject: [PATCH] * Notifications: fix wrong condition leading to infinite recursion (causing timeout) and high database load --- notifications/inc/class.notifications_popup.inc.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/notifications/inc/class.notifications_popup.inc.php b/notifications/inc/class.notifications_popup.inc.php index 248732d6d3..28b2bff3cf 100644 --- a/notifications/inc/class.notifications_popup.inc.php +++ b/notifications/inc/class.notifications_popup.inc.php @@ -155,17 +155,18 @@ class notifications_popup implements notifications_iface $db = $GLOBALS['egw']->db; $result = []; + $cut_off_date = $db->quote(Api\DateTime::to(notifications_ajax::$cut_off_date, Api\DateTime::DATABASE)); if (($total = $db->select(self::_notification_table, 'COUNT(*)', [ 'account_id' => $_account_id, 'notify_type' => self::_type, - 'notify_created > '.($cut_off=$db->quote(Api\DateTime::to(notifications_ajax::$cut_off_date, Api\DateTime::DATABASE))), + 'notify_created > '.$cut_off_date, 'notify_app_id IS NULL', ], __LINE__, __FILE__, false, '', self::_appname)->fetchColumn()+ $db->select( '('.$db->select(self::_notification_table, 'notify_app,notify_app_id', [ 'account_id' => $_account_id, 'notify_type' => self::_type, - 'notify_created > '.($cut_off=$db->quote(Api\DateTime::to(notifications_ajax::$cut_off_date, Api\DateTime::DATABASE))), + 'notify_created > '.$cut_off_date, 'notify_app_id IS NOT NULL', ], false, false, false, 'GROUP BY notify_app,notify_app_id', self::_appname).') AS app_ids', 'COUNT(*)', false, __LINE__, __FILE__, false, '', self::_appname)->fetchColumn() @@ -179,7 +180,7 @@ class notifications_popup implements notifications_iface foreach ($rs=$db->select(self::_notification_table, '*', [ 'account_id' => $_account_id, 'notify_type' => self::_type, - 'notify_created > ' . $cut_off, + 'notify_created > '.$cut_off_date, ], __LINE__, __FILE__, $n, 'ORDER BY notify_id DESC', self::_appname, $chunk_size) as $notification) { $actions = null; @@ -219,9 +220,9 @@ class notifications_popup implements notifications_iface } $n += $chunk_size; } - while(!$notification || count($result) < min($num_rows, $total)); + while($notification && count($result) < min($num_rows, $total)); - return ['rows' => array_values($result), 'total'=> $total]; + return ['rows' => array_values($result), 'total' => $total]; } }