A platform for community discussion. Free, open, simple.
PERF: Look up user menu message notification authors once
Régis Hanol796e1fff7351
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rbindex 0e68f2f0825..25a1a537a01 100644--- a/app/controllers/users_controller.rb+++ b/app/controllers/users_controller.rb@@ -2109,8 +2109,10 @@ class UsersController < ApplicationControllerNotification.filter_inaccessible_topic_notifications(guardian, read_notifications)end+ notifications = unread_notifications + read_notifications.to_a+ Notification.populate_acting_user(notifications) if notifications.present?+if unread_notifications.present?- Notification.populate_acting_user(unread_notifications)serialized_unread_notifications =ActiveModel::ArraySerializer.new(unread_notifications,@@ -2122,7 +2124,6 @@ class UsersController < ApplicationControllerserialized_messages = serialize_data(messages, UserMenuMessageSerializer) if messagesif read_notifications.present?- Notification.populate_acting_user(read_notifications)serialized_read_notifications =ActiveModel::ArraySerializer.new(read_notifications,diff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rbindex af18ffa4511..801f7e3393f 100644--- a/spec/requests/users_controller_spec.rb+++ b/spec/requests/users_controller_spec.rb@@ -9122,6 +9122,14 @@ RSpec.describe UsersController doendend+ it "looks up acting users of unread and read notifications at once" do+ SiteSetting.show_user_menu_avatars = true++ queries = track_sql_queries { get "/u/#{user.username}/user-menu-private-messages" }+ expect(response.status).to eq(200)+ expect(queries.grep(/username_lower/).size).to eq(1)+ end+it "sends an array of read group_message_summary notifications" doread_group_message_summary_notification2 =Fabricate(