optimize search
This commit is contained in:
@@ -36,7 +36,7 @@ class TemplatesDashboardController < ApplicationController
|
|||||||
@templates = @templates.where(folder_id: @default_folder.id) if params[:q].blank?
|
@templates = @templates.where(folder_id: @default_folder.id) if params[:q].blank?
|
||||||
end
|
end
|
||||||
|
|
||||||
@pagy, @templates = load_templates(@templates, @pagy.count)
|
@pagy, @templates = load_templates(@templates, @pagy.count, show_shared_inline: @show_shared_inline)
|
||||||
|
|
||||||
if params[:q].present? && @templates.blank?
|
if params[:q].present? && @templates.blank?
|
||||||
@related_submissions_pagy, @related_submissions = load_related_submissions
|
@related_submissions_pagy, @related_submissions = load_related_submissions
|
||||||
@@ -46,9 +46,16 @@ class TemplatesDashboardController < ApplicationController
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def load_templates(templates, folders_count)
|
def load_templates(templates, folders_count, show_shared_inline: false)
|
||||||
templates = templates.preload(:author, :template_accesses)
|
templates = templates.preload(:author, :template_accesses)
|
||||||
templates = Templates.search(current_user, templates, params[:q])
|
|
||||||
|
templates =
|
||||||
|
if show_shared_inline
|
||||||
|
Templates.search_shared(current_user, templates, params[:q])
|
||||||
|
else
|
||||||
|
Templates.search(current_user, templates, params[:q])
|
||||||
|
end
|
||||||
|
|
||||||
templates = Templates::Order.call(templates, current_user, selected_order)
|
templates = Templates::Order.call(templates, current_user, selected_order)
|
||||||
|
|
||||||
limit =
|
limit =
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class TemplatesSharedController < ApplicationController
|
|||||||
@templates = @templates.preload(:author, :template_accesses, :template_sharings)
|
@templates = @templates.preload(:author, :template_accesses, :template_sharings)
|
||||||
.order(id: :desc)
|
.order(id: :desc)
|
||||||
|
|
||||||
@templates = Templates.search(current_user, @templates, params[:q])
|
@templates = Templates.search_shared(current_user, @templates, params[:q])
|
||||||
|
|
||||||
@pagy, @templates = pagy_auto(@templates, limit: 12)
|
@pagy, @templates = pagy_auto(@templates, limit: 12)
|
||||||
|
|
||||||
|
|||||||
+16
-2
@@ -70,6 +70,21 @@ module Templates
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def search_shared(current_user, templates, keyword)
|
||||||
|
return templates if keyword.blank?
|
||||||
|
|
||||||
|
if Docuseal.fulltext_search?
|
||||||
|
templates.where(
|
||||||
|
id: SearchEntry.where(record_type: 'Template')
|
||||||
|
.where(account_id: current_user.account.linked_account_account&.account_id)
|
||||||
|
.where(*SearchEntries.build_tsquery(keyword))
|
||||||
|
.select(:record_id)
|
||||||
|
)
|
||||||
|
else
|
||||||
|
plain_search(templates, keyword)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def plain_search(templates, keyword)
|
def plain_search(templates, keyword)
|
||||||
return templates if keyword.blank?
|
return templates if keyword.blank?
|
||||||
|
|
||||||
@@ -83,8 +98,7 @@ module Templates
|
|||||||
|
|
||||||
templates.where(
|
templates.where(
|
||||||
id: SearchEntry.where(record_type: 'Template')
|
id: SearchEntry.where(record_type: 'Template')
|
||||||
.where(account_id: [current_user.account_id,
|
.where(account_id: current_user.account_id)
|
||||||
current_user.account.linked_account_account&.account_id].compact)
|
|
||||||
.where(*SearchEntries.build_tsquery(keyword))
|
.where(*SearchEntries.build_tsquery(keyword))
|
||||||
.select(:record_id)
|
.select(:record_id)
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user