diff --git a/VERSION b/VERSION index 4e00d0ac0..24a57f28a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.14.4 +1.14.5 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 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