summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarin Jankovski <marin@gitlab.com>2014-02-03 16:02:44 +0100
committerMarin Jankovski <marin@gitlab.com>2014-02-03 16:02:44 +0100
commit4b0fb02816e91eac09ce84c2383b0275b35aef97 (patch)
tree2ee276b3c46a2a76f80b6675da707d05eda0f310
parent70fb26a6b7091aee9875970f070a6801e35de764 (diff)
downloadgitlab-ce-4b0fb02816e91eac09ce84c2383b0275b35aef97.tar.gz
Do not load all projects all the time.
-rw-r--r--app/services/filtering_service.rb34
1 files changed, 20 insertions, 14 deletions
diff --git a/app/services/filtering_service.rb b/app/services/filtering_service.rb
index 76a3d71df56..92974546b86 100644
--- a/app/services/filtering_service.rb
+++ b/app/services/filtering_service.rb
@@ -24,10 +24,10 @@ class FilteringService
@current_user = current_user
@params = params
- items = by_scope
+ items = init_collection
+ 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)
@@ -37,24 +37,30 @@ class FilteringService
private
- def by_scope
+ def init_collection
table_name = klass.table_name
+ return klass.of_projects(Project.public_only) unless current_user
+
+ if project
+ if current_user.can?(:read_project, project)
+ project.send(table_name)
+ else
+ []
+ end
+ else
+ klass.of_projects(current_user.authorized_projects)
+ end
+ end
+
+ def by_scope(items)
case params[:scope]
when 'created-by-me', 'authored' then
- current_user.send(table_name)
+ klass.where(author_id: current_user.id)
when 'all' then
- if current_user
- if project && (project.public? || project.internal?)
- klass.of_projects(Project.public_or_internal_only(current_user))
- else
- klass.of_projects(current_user.authorized_projects.pluck(:id))
- end
- else
- klass.of_projects(Project.public_only)
- end
+ klass
when 'assigned-to-me' then
- current_user.send("assigned_#{table_name}")
+ klass.where(assignee_id: current_user.id)
else
raise 'You must specify default scope'
end