mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-03-03 19:24:48 +08:00
Optimized repository cells search by replacing Rails select statement with raw SQL statement. [SCI-1357]
This commit is contained in:
parent
05ea00a5d3
commit
1f0eeeaecb
1 changed files with 28 additions and 6 deletions
|
@ -197,12 +197,34 @@ class RepositoryDatatable < AjaxDatatablesRails::Base
|
|||
params[:search][:value].present?
|
||||
search_val = params[:search][:value]
|
||||
|
||||
filtered_rows = repo_rows.select do |r|
|
||||
row_cells = [r.name, r.created_at.strftime(Constants::DATE_FORMAT),
|
||||
r.created_by.full_name]
|
||||
row_cells.push(*r.repository_cells.collect { |c| c.value.data })
|
||||
row_cells.any? { |c| c.include?(search_val) }
|
||||
end
|
||||
filtered_rows = repo_rows.find_by_sql(
|
||||
"SELECT DISTINCT repository_rows.*
|
||||
FROM repository_rows
|
||||
INNER JOIN (
|
||||
SELECT users.*
|
||||
FROM users
|
||||
) AS users
|
||||
ON users.id = repository_rows.created_by_id
|
||||
LEFT OUTER JOIN (
|
||||
SELECT repository_cells.repository_row_id,
|
||||
repository_text_values.data AS text_value,
|
||||
to_char(repository_date_values.data, 'DD.MM.YYYY HH24:MI')
|
||||
AS date_value
|
||||
FROM repository_cells
|
||||
INNER JOIN repository_text_values
|
||||
ON repository_text_values.id = repository_cells.value_id
|
||||
FULL OUTER JOIN repository_date_values
|
||||
ON repository_date_values.id = repository_cells.value_id
|
||||
) AS values
|
||||
ON values.repository_row_id = repository_rows.id
|
||||
WHERE repository_rows.repository_id = #{@repository.id}
|
||||
AND (repository_rows.name ILIKE '%#{search_val}%'
|
||||
OR to_char(repository_rows.created_at, 'DD.MM.YYYY HH24:MI')
|
||||
ILIKE '%#{search_val}%'
|
||||
OR users.full_name ILIKE '%#{search_val}%'
|
||||
OR text_value ILIKE '%#{search_val}%'
|
||||
OR date_value ILIKE '%#{search_val}%')"
|
||||
)
|
||||
repo_rows.where(id: filtered_rows)
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue