Files
fizzy/app/models/filter.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

76 lines
2.1 KiB
Ruby

class Filter < ApplicationRecord
include Fields, Params, Resources, Summarized
belongs_to :account, default: -> { Current.account }
belongs_to :creator, class_name: "User", default: -> { Current.user }
class << self
def from_params(params)
find_by_params(params) || build(params)
end
def remember(attrs)
create!(attrs)
rescue ActiveRecord::RecordNotUnique
find_by_params(attrs).tap(&:touch)
end
end
def cards
@cards ||= begin
result = creator.accessible_cards.published
result = result.indexed_by(indexed_by)
result = result.sorted_by(sorted_by)
result = result.where(id: card_ids) if card_ids.present?
result = result.where.missing(:not_now) unless include_not_now_cards?
result = result.open unless include_closed_cards?
result = result.unassigned if assignment_status.unassigned?
result = result.assigned_to(assignees.ids) if assignees.present?
result = result.where(creator_id: creators.ids) if creators.present?
result = result.where(board: boards.ids) if boards.present?
result = result.tagged_with(tags.ids) if tags.present?
result = result.where("cards.created_at": creation_window) if creation_window
result = result.closed_at_window(closure_window) if closure_window
result = result.closed_by(closers) if closers.present?
result = terms.reduce(result) do |result, term|
result.mentioning(term, user: creator)
end
result
end
end
def empty?
self.class.normalize_params(as_params).blank?
end
def single_board
boards.first if boards.one?
end
def single_workflow
boards.first.workflow if boards.pluck(:workflow_id).uniq.one?
end
def cacheable?
boards.exists?
end
def cache_key
ActiveSupport::Cache.expand_cache_key params_digest, "filter"
end
def only_closed?
indexed_by.closed? || closure_window || closers.present?
end
private
def include_closed_cards?
only_closed? || card_ids.present? || creator_ids.present?
end
def include_not_now_cards?
indexed_by.not_now? || card_ids.present?
end
end