Files
fizzy/app/controllers/prompts/cards_controller.rb
T
Donal McBreen ddd7fe082a Ensure the mentioning scope search works
Include the filter by accessible board ids to avoid large joins from the
search_index table. Drop the unused search scope.
2025-11-17 09:12:17 -05:00

40 lines
822 B
Ruby

class Prompts::CardsController < ApplicationController
MAX_RESULTS = 10
def index
@cards = if filter_param.present?
prepending_exact_matches_by_id(search_cards)
else
published_cards.latest
end
if stale? etag: @cards
render layout: false
end
end
private
def filter_param
params[:filter]
end
def search_cards
published_cards
.mentioning(params[:filter], board_ids: Current.user.board_ids)
.reverse_chronologically
.limit(MAX_RESULTS)
end
def published_cards
Current.user.accessible_cards.published
end
def prepending_exact_matches_by_id(cards)
if card_by_id = Current.user.accessible_cards.find_by_id(params[:filter])
[ card_by_id ] + cards
else
cards
end
end
end