diff options
author | Oswaldo Ferreira <oswaldo@gitlab.com> | 2017-01-14 21:22:38 -0200 |
---|---|---|
committer | Oswaldo Ferreira <oswaldo@gitlab.com> | 2017-01-14 21:22:38 -0200 |
commit | e613fa583b57d16da9cb88d9866aaefe11e1696b (patch) | |
tree | ebf1694cd0753e6327a63c57538e48aedce7312e | |
parent | 77756efc22af33dd1cdb16671e39192d5761eaf6 (diff) | |
download | gitlab-ce-25503-restrict-issuables-projects-on-dashboard-perf-improvement.tar.gz |
Restrict issuables projects for author and assignee filter25503-restrict-issuables-projects-on-dashboard-perf-improvement
-rw-r--r-- | app/finders/issuable_finder.rb | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/app/finders/issuable_finder.rb b/app/finders/issuable_finder.rb index 1576fc80a6b..b7ae76fcc43 100644 --- a/app/finders/issuable_finder.rb +++ b/app/finders/issuable_finder.rb @@ -32,11 +32,15 @@ class IssuableFinder items = by_scope(items) items = by_state(items) items = by_group(items) - items = by_project(items) items = by_search(items) items = by_milestone(items) items = by_assignee(items) items = by_author(items) + # Project filter MUST be done after assignee's and author's filter. + # We must restrict the projects query by the projects from the issuables a + # user is assigned or authored, avoiding a non-performatic query. + # Futher explained on: https://gitlab.com/gitlab-org/gitlab-ce/issues/25503 + items = by_project(items) items = by_label(items) items = by_due_date(items) items = by_non_archived(items) @@ -115,7 +119,7 @@ class IssuableFinder elsif group GroupProjectsFinder.new(group).execute(current_user) else - ProjectsFinder.new.execute(current_user) + ProjectsFinder.new.execute(current_user, @restricted_project_ids) end @projects = projects.with_feature_available_for_user(klass, current_user).reorder(nil) @@ -287,6 +291,7 @@ class IssuableFinder def by_assignee(items) if assignee items = items.where(assignee_id: assignee.id) + restrict_projects_by!(items) elsif no_assignee? items = items.where(assignee_id: nil) elsif assignee_id? || assignee_username? # assignee not found @@ -299,6 +304,7 @@ class IssuableFinder def by_author(items) if author items = items.where(author_id: author.id) + restrict_projects_by!(items) elsif no_author? items = items.where(author_id: nil) elsif author_id? || author_username? # author not found @@ -308,6 +314,14 @@ class IssuableFinder items end + def restrict_projects_by!(items) + @restricted_project_ids = if @restricted_project_ids + @restricted_project_ids.merge(items.select(:project_id)).select(:project_id) + else + items.select(:project_id) + end + end + def filter_by_upcoming_milestone? params[:milestone_title] == Milestone::Upcoming.name end |