Avoid a double join alias when loading shared sidebar rooms

Chaining without_direct_rooms with with_ordered_room joined rooms as
`room` while still ordering on `rooms.name`. Load shared rooms in one
scope instead.

Co-authored-by: Thomas Klemm <github@tklemm.eu>
This commit is contained in:
Cursor Agent
2026-10-05 12:36:42 +00:00
parent fbeb1ae993
commit 88fbeedc75
2 changed files with 2 additions and 1 deletions
+1 -1
View File
@@ -4,7 +4,7 @@ class Users::SidebarsController < ApplicationController
def show
visible_memberships = Current.user.memberships.visible
@direct_memberships = visible_memberships.with_direct_rooms
@other_memberships = visible_memberships.without_direct_rooms.with_ordered_room
@other_memberships = visible_memberships.with_ordered_shared_rooms
@direct_placeholder_users = find_direct_placeholder_users
end
+1
View File
@@ -10,6 +10,7 @@ class Membership < ApplicationRecord
scope :with_ordered_room, -> { includes(:room).joins(:room).order("LOWER(rooms.name)") }
scope :with_direct_rooms, -> { includes(:room).joins(:room).where(rooms: { type: "Rooms::Direct" }).order(rooms: { updated_at: :desc }) }
scope :with_ordered_shared_rooms, -> { includes(:room).joins(:room).where.not(rooms: { type: "Rooms::Direct" }).order("LOWER(rooms.name)") }
scope :without_direct_rooms, -> { joins(:room).where.not(room: { type: "Rooms::Direct" }) }
scope :visible, -> { where.not(involvement: :invisible) }