From 77e127dcfe0b242f87f153bcc0d3673b502ddab9 Mon Sep 17 00:00:00 2001 From: ulferts Date: Wed, 13 Dec 2023 13:04:34 +0100 Subject: [PATCH] improve the notification performance This improvements has two parts: * Avoid reapplying the visibility check for notifications. * Merging the constraints rather then having them in a subselect. --- lib/api/v3/notifications/notifications_api.rb | 4 +++- lib/api/v3/utilities/endpoints/index.rb | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/api/v3/notifications/notifications_api.rb b/lib/api/v3/notifications/notifications_api.rb index fd87cbd99752..9acaf955b2c9 100644 --- a/lib/api/v3/notifications/notifications_api.rb +++ b/lib/api/v3/notifications/notifications_api.rb @@ -60,8 +60,10 @@ def bulk_update_status(attributes) end end + # No need to reapply the visibility scope here as this will be done by the used + # NotificationQuery. get &::API::V3::Utilities::Endpoints::SqlFallbackedIndex - .new(model: Notification, scope: -> { notification_scope }) + .new(model: Notification, scope: -> { Notification.where.not(read_ian: nil) }) .mount post :read_ian do diff --git a/lib/api/v3/utilities/endpoints/index.rb b/lib/api/v3/utilities/endpoints/index.rb index 4ac995119a89..f01e04b1ba7a 100644 --- a/lib/api/v3/utilities/endpoints/index.rb +++ b/lib/api/v3/utilities/endpoints/index.rb @@ -164,7 +164,7 @@ def apply_scope_constraint(constraint, result_scope) else result_scope .includes(constraint.includes_values) - .where id: constraint.select(:id) + .merge constraint end end end