Files
once-campfire/app/controllers/searches_controller.rb
T
Marcello Costagliola edaab3e5d1 Read the newest search matches off the index instead of sorting them all
Search showed the last 100 matches by created_at, so SQLite collected every
message containing the words and sorted them before keeping a page. A common
word in a large account meant sorting most of its history on every search.

Ordering by the full-text index's rowid, which is the message id, lets SQLite
walk the index from the newest match and stop once the page is full.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JVFo3Lt9T8M5NR7KxVvsZ2
2026-10-05 02:50:48 +02:00

33 lines
711 B
Ruby

class SearchesController < ApplicationController
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 = Current.user.reachable_messages.search(query).with_presentation.last_page_of_matches(100)
else
@messages = Message.none
end
end
def query
params[:q]&.gsub(/[^[:word:]]/, " ")
end
end