mirror of
https://github.com/basecamp/once-campfire.git
synced 2026-10-09 00:00:12 +09:00
ac73267b07
Transfer the C completed-response cache lesson into Rails, keeping authentication, room checks and cookies per request. A persistent read-only SQLite observer detects local and foreign commits and rejects racing admission. Whole-page misses render fresh to avoid stale nested fragments; message ETags reflect token-neutral presentation.
23 lines
878 B
Ruby
23 lines
878 B
Ruby
class Users::SidebarsController < ApplicationController
|
|
DIRECT_PLACEHOLDERS = 20
|
|
around_action :cache_read_response, only: :show
|
|
|
|
def show
|
|
visible_memberships = Current.user.memberships.visible
|
|
@direct_memberships = visible_memberships.with_direct_rooms
|
|
@other_memberships = visible_memberships.with_ordered_room.without_direct_rooms
|
|
|
|
@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
|