diff --git a/app/helpers/reports_helper.rb b/app/helpers/reports_helper.rb index 38424c98b..5f9106c99 100644 --- a/app/helpers/reports_helper.rb +++ b/app/helpers/reports_helper.rb @@ -138,8 +138,8 @@ module ReportsHelper end def assigned_repositories_in_project_list(project) - live_repositories = Repository.assigned_in_project(project) - snapshots = RepositorySnapshot.assigned_in_project(project) + live_repositories = Repository.assigned_to_project(project) + snapshots = RepositorySnapshot.assigned_to_project(project) snapshots.each { |snapshot| snapshot.name = "#{snapshot.name} #{t('projects.reports.index.deleted')}" } (live_repositories + snapshots).sort_by { |r| r.name.downcase } diff --git a/app/models/project.rb b/app/models/project.rb index d88817b62..501927bd3 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -211,8 +211,8 @@ class Project < ApplicationRecord end def assigned_repositories_and_snapshots - live_repositories = Repository.assigned_in_project(self) - snapshots = RepositorySnapshot.assigned_in_project(self) + live_repositories = Repository.assigned_to_project(self) + snapshots = RepositorySnapshot.assigned_to_project(self) (live_repositories + snapshots).sort_by { |r| r.name.downcase } end diff --git a/app/models/report.rb b/app/models/report.rb index 507914e01..87d49b5e4 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -131,12 +131,10 @@ class Report < ApplicationRecord result_children) end - module_children += gen_element_content(my_module, nil, 'my_module_activity', true, 'asc') - repositories = project.assigned_repositories_and_snapshots + module_children += gen_element_content(my_module, nil, 'my_module_activity', true, 'asc') module_children += gen_element_content(my_module, repositories, 'my_module_repository', true, 'asc') - modules += gen_element_content(my_module, nil, 'my_module', true, nil, module_children) end diff --git a/app/models/repository.rb b/app/models/repository.rb index b27be9fa4..6dec83b53 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -36,6 +36,12 @@ class Repository < RepositoryBase .distinct } + scope :assigned_to_project, lambda { |project| + accessible_by_teams(project.team) + .joins(repository_rows: { my_module_repository_rows: { my_module: { experiment: :project } } }) + .where(repository_rows: { my_module_repository_rows: { my_module: { experiments: { project: project } } } }) + } + def self.within_global_limits? return true unless Rails.configuration.x.global_repositories_limit.positive? @@ -83,12 +89,6 @@ class Repository < RepositoryBase end end - def self.assigned_in_project(project) - accessible_by_teams(project.team) - .joins(repository_rows: { my_module_repository_rows: { my_module: { experiment: :project } } }) - .where(repository_rows: { my_module_repository_rows: { my_module: { experiments: { project: project } } } }) - end - def default_columns_count Constants::REPOSITORY_TABLE_DEFAULT_STATE['length'] end diff --git a/app/models/repository_snapshot.rb b/app/models/repository_snapshot.rb index 297584860..57cc77d55 100644 --- a/app/models/repository_snapshot.rb +++ b/app/models/repository_snapshot.rb @@ -15,14 +15,14 @@ class RepositorySnapshot < RepositoryBase validates :status, presence: true validate :only_one_selected_for_my_module, if: ->(obj) { obj.changed.include? :selected } - def self.assigned_in_project(project) + scope :assigned_to_project, lambda { |project| joins(my_module: { experiment: :project }) .where('experiments.project_id = ?', project.id) .left_outer_joins(:original_repository) .where(original_repositories_repositories: { id: nil }) .select('DISTINCT ON ("repositories"."parent_id") "repositories".*') .order(:parent_id, updated_at: :desc) - end + } def default_columns_count Constants::REPOSITORY_SNAPSHOT_TABLE_DEFAULT_STATE['length']