Files
once-campfire/app/controllers/users/sidebars_controller.rb
T
Cursor Agent fbeb1ae993 Query sidebar directs and shared rooms separately
Load visible direct memberships ordered by room recency and other
rooms ordered by name, instead of hydrating every membership and
splitting them in Ruby.

Fixes #307.

Co-authored-by: Thomas Klemm <github@tklemm.eu>
2026-10-05 12:35:35 +00:00

22 lines
828 B
Ruby

class Users::SidebarsController < ApplicationController
DIRECT_PLACEHOLDERS = 20
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
@direct_placeholder_users = find_direct_placeholder_users
end
private
def find_direct_placeholder_users
exclude_user_ids = user_ids_already_in_direct_rooms_with_current_user.including(Current.user.id)
User.active.where.not(id: exclude_user_ids).order(:created_at).limit([ DIRECT_PLACEHOLDERS - exclude_user_ids.count, 0 ].max)
end
def user_ids_already_in_direct_rooms_with_current_user
Membership.where(room_id: Current.user.rooms.directs.pluck(:id)).pluck(:user_id).uniq
end
end