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.
34 lines
718 B
Ruby
34 lines
718 B
Ruby
class SearchesController < ApplicationController
|
|
around_action :cache_read_response, only: :index
|
|
before_action :set_messages
|
|
|
|
def index
|
|
@query = query if query.present?
|
|
@recent_searches = Current.user.searches.ordered
|
|
@return_to_room = last_room_visited
|
|
end
|
|
|
|
def create
|
|
Current.user.searches.record(query)
|
|
redirect_to searches_url(q: query)
|
|
end
|
|
|
|
def clear
|
|
Current.user.searches.destroy_all
|
|
redirect_to searches_url
|
|
end
|
|
|
|
private
|
|
def set_messages
|
|
if query.present?
|
|
@messages = Message.search_reachable(Current.user, query)
|
|
else
|
|
@messages = Message.none
|
|
end
|
|
end
|
|
|
|
def query
|
|
params[:q]&.gsub(/[^[:word:]]/, " ")
|
|
end
|
|
end
|