From 37f53542fe1c36c6126932cbb3840f6d4659104e Mon Sep 17 00:00:00 2001 From: Claire Date: Thu, 13 Jun 2024 14:42:40 +0200 Subject: [PATCH] Fix limit handling in grouped notifications CTE (#30685) --- app/models/notification.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/models/notification.rb b/app/models/notification.rb index e3deaa5348..01abe74f5e 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -152,6 +152,7 @@ class Notification < ApplicationRecord .limit(1), query .joins('CROSS JOIN grouped_notifications') + .where('array_length(grouped_notifications.groups, 1) < :limit', limit: limit) .where('notifications.id < grouped_notifications.id') .where.not("COALESCE(notifications.group_key, 'ungrouped-' || notifications.id) = ANY(grouped_notifications.groups)") .select('notifications.*', "array_append(grouped_notifications.groups, COALESCE(notifications.group_key, 'ungrouped-' || notifications.id))") @@ -179,6 +180,7 @@ class Notification < ApplicationRecord .limit(1), query .joins('CROSS JOIN grouped_notifications') + .where('array_length(grouped_notifications.groups, 1) < :limit', limit: limit) .where('notifications.id > grouped_notifications.id') .where.not("COALESCE(notifications.group_key, 'ungrouped-' || notifications.id) = ANY(grouped_notifications.groups)") .select('notifications.*', "array_append(grouped_notifications.groups, COALESCE(notifications.group_key, 'ungrouped-' || notifications.id))")