Merge pull request #4206 from marc1706/ticket/14519

[ticket/14519] Skip query if all unread notifications are retrieved
This commit is contained in:
Máté Bartus 2016-03-08 22:09:02 +01:00
commit 7c45ed0733

View file

@ -186,6 +186,7 @@ class manager
if (!$options['count_total'] || $total_count)
{
$rowset = array();
$selected_unread_count = 0;
// Get the main notifications
$sql = 'SELECT n.*, nt.notification_type_name
@ -200,11 +201,12 @@ class manager
while ($row = $this->db->sql_fetchrow($result))
{
$rowset[$row['notification_id']] = $row;
$selected_unread_count += (int) !$row['notification_read'];
}
$this->db->sql_freeresult($result);
// Get all unread notifications
if ($unread_count && $options['all_unread'] && !empty($rowset))
if ($selected_unread_count < $unread_count && $options['all_unread'] && !empty($rowset))
{
$sql = 'SELECT n.*, nt.notification_type_name
FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt