Files
fizzy/app/controllers/prompts/cards_controller.rb
T
Donal McBreen 3aa4a1a562 Shard the search index into 16 tables
Create search_index_0 to search_index_15 tables and shard each index by
account id. MySQL has no ability to pre-filter fulltext indexes by
another field so this is the best bet for improving performance.

Each fulltest index internally creates 11 sub tables (see
https://dev.mysql.com/doc/refman/8.4/en/innodb-fulltext-index.html) so
actually we have 192 tables in total here.

The search_index table name is generated dynamically based on the
account_id.
2025-11-17 09:12:17 -05:00

40 lines
807 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], user: Current.user)
.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