From 4ee9eb31344b8ce065bfc275af2b9688dafdb1b4 Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Mon, 17 Sep 2018 15:46:56 +0200 Subject: [PATCH 1/3] Improve search speed on files and inventories [SCI-2739] --- app/models/asset.rb | 40 ++++++++++++++++++++++++---------------- app/models/repository.rb | 8 +++++--- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/app/models/asset.rb b/app/models/asset.rb index 408ba5435..cbe9fc636 100644 --- a/app/models/asset.rb +++ b/app/models/asset.rb @@ -98,23 +98,31 @@ class Asset < ApplicationRecord options = {} ) - project_ids = - Project - .search(user, include_archived, nil, Constants::SEARCH_NO_LIMIT) - .pluck(:id) - team_ids = user.teams.pluck(:id) + teams = user.teams.select(:id) - new_query = - Asset - .distinct - .left_outer_joins(:asset_text_datum) - .left_outer_joins( - step: { protocol: { my_module: { experiment: :project } } } - ) - .left_outer_joins(result: { my_module: { experiment: :project } }) - .left_outer_joins(repository_cell: { repository_column: :repository }) - .where('projects.id IN (?) OR repositories.team_id IN (?)', - project_ids, team_ids) + assets_in_steps = Asset.joins(:step).where( + 'steps.id IN (?)', + Step.search(user, include_archived, nil, Constants::SEARCH_NO_LIMIT) + .select(:id) + ).pluck(:id) + + assets_in_results = Asset.joins(:result).where( + 'results.id IN (?)', + Result.search(user, include_archived, nil, Constants::SEARCH_NO_LIMIT) + .select(:id) + ).pluck(:id) + + assets_in_inventories = Asset.joins( + repository_cell: { repository_column: :repository } + ).where('repositories.team_id IN (?)', teams).pluck(:id) + + assets = + Asset.distinct + .where('assets.id IN (?) OR assets.id IN (?) OR assets.id IN (?)', + assets_in_steps, assets_in_results, assets_in_inventories) + + new_query = Asset.left_outer_joins(:asset_text_datum) + .from(assets, 'assets') a_query = s_query = '' diff --git a/app/models/repository.rb b/app/models/repository.rb index 04dcf5f35..831b69d21 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -34,16 +34,19 @@ class Repository < ApplicationRecord repository = nil, options = {} ) - repositories = repository ? repository : Repository.where(team: user.teams) + repositories = repository || Repository.where(team: user.teams) includes_json = { repository_cells: Extends::REPOSITORY_SEARCH_INCLUDES } searchable_attributes = ['repository_rows.name', 'users.full_name'] + Extends::REPOSITORY_EXTRA_SEARCH_ATTR + all_rows = RepositoryRow.where(repository: repositories) + new_query = RepositoryRow + .distinct + .from(all_rows, 'repository_rows') .left_outer_joins(:created_by) .left_outer_joins(includes_json) - .where(repository: repositories) .where_attributes_like(searchable_attributes, query, options) # Show all results if needed @@ -56,7 +59,6 @@ class Repository < ApplicationRecord .group('repositories.id') else new_query - .distinct .limit(Constants::SEARCH_LIMIT) .offset((page - 1) * Constants::SEARCH_LIMIT) end From 872a48082ae4b58465d074557b3ea78078a6b496 Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Tue, 18 Sep 2018 15:03:19 +0200 Subject: [PATCH 2/3] Remove Samples from search controller [SCI-2739] --- app/controllers/search_controller.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 0a2c90aea..0a5f52d69 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -173,7 +173,6 @@ class SearchController < ApplicationController @protocol_search_count = fetch_cached_count Protocol @step_search_count = fetch_cached_count Step @checklist_search_count = fetch_cached_count Checklist - @sample_search_count = fetch_cached_count Sample @repository_search_count_total = count_by_repository @asset_search_count = fetch_cached_count Asset @table_search_count = fetch_cached_count Table @@ -188,7 +187,6 @@ class SearchController < ApplicationController @search_results_count += @protocol_search_count @search_results_count += @step_search_count @search_results_count += @checklist_search_count - @search_results_count += @sample_search_count @search_results_count += @repository_search_count_total @search_results_count += @asset_search_count @search_results_count += @table_search_count From 90caad3c8516e23ae9bf2ef0a07ff8dc6e8ebfdd Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Wed, 19 Sep 2018 14:37:43 +0200 Subject: [PATCH 3/3] Update VERSION to 1.14.5 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 4e00d0ac0..24a57f28a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.14.4 +1.14.5