summaryrefslogtreecommitdiff
path: root/app/finders
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2017-07-07 18:31:50 +0200
committerJames Lopez <james@jameslopez.es>2017-07-07 18:31:50 +0200
commitcda7cbde03ca5908144df2d37f32e4142de73174 (patch)
tree1b1f732fb16d7fae48da9d62e4d4ab5a4459310b /app/finders
parent5e66c6568ba2a528e037eaf9d466cfb489b52891 (diff)
downloadgitlab-ce-cda7cbde03ca5908144df2d37f32e4142de73174.tar.gz
refactor created at filter to use model scopes
Diffstat (limited to 'app/finders')
-rw-r--r--app/finders/created_at_filter.rb8
-rw-r--r--app/finders/issuable_finder.rb4
-rw-r--r--app/finders/users_finder.rb2
3 files changed, 11 insertions, 3 deletions
diff --git a/app/finders/created_at_filter.rb b/app/finders/created_at_filter.rb
new file mode 100644
index 00000000000..ac9ac77732c
--- /dev/null
+++ b/app/finders/created_at_filter.rb
@@ -0,0 +1,8 @@
+module CreatedAtFilter
+ def by_created_at(items)
+ items = items.created_before(params[:created_before]) if params[:created_before].present?
+ items = items.created_after(params[:created_after]) if params[:created_after].present?
+
+ items
+ end
+end
diff --git a/app/finders/issuable_finder.rb b/app/finders/issuable_finder.rb
index 39427d83669..6e37c10166d 100644
--- a/app/finders/issuable_finder.rb
+++ b/app/finders/issuable_finder.rb
@@ -19,7 +19,7 @@
# iids: integer[]
#
class IssuableFinder
- include Gitlab::Database::CreatedAtFilter
+ include CreatedAtFilter
NONE = '0'.freeze
IRRELEVANT_PARAMS_FOR_CACHE_KEY = %i[utf8 sort page].freeze
@@ -34,6 +34,7 @@ class IssuableFinder
def execute
items = init_collection
items = by_scope(items)
+ items = by_created_at(items)
items = by_state(items)
items = by_group(items)
items = by_search(items)
@@ -44,7 +45,6 @@ class IssuableFinder
items = by_iids(items)
items = by_milestone(items)
items = by_label(items)
- items = by_created_at(items)
# Filtering by project HAS TO be the last because we use the project IDs yielded by the issuable query thus far
items = by_project(items)
diff --git a/app/finders/users_finder.rb b/app/finders/users_finder.rb
index c6bfc380c1c..33f7ae90598 100644
--- a/app/finders/users_finder.rb
+++ b/app/finders/users_finder.rb
@@ -14,7 +14,7 @@
# external: boolean
#
class UsersFinder
- include Gitlab::Database::CreatedAtFilter
+ include CreatedAtFilter
attr_accessor :current_user, :params