Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
ad5e37984a15
Commit
cda7cbde
authored
Jul 07, 2017
by
James Lopez
Browse files
refactor created at filter to use model scopes
parent
d67a7ffe2556
Changes
7
Hide whitespace changes
Inline
Side-by-side
app/finders/created_at_filter.rb
0 → 100644
View file @
ad5e3798
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
app/finders/issuable_finder.rb
View file @
ad5e3798
...
...
@@ -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 @@ def initialize(current_user, params = {})
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 @@ def execute
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
)
...
...
app/finders/users_finder.rb
View file @
ad5e3798
...
...
@@ -14,7 +14,7 @@
# external: boolean
#
class
UsersFinder
include
Gitlab
::
Database
::
CreatedAtFilter
include
CreatedAtFilter
attr_accessor
:current_user
,
:params
...
...
app/models/concerns/created_at_filterable.rb
0 → 100644
View file @
ad5e3798
module
CreatedAtFilterable
extend
ActiveSupport
::
Concern
included
do
scope
:created_before
,
->
(
date
)
{
where
(
scoped_table
[
:created_at
].
lteq
(
date
))
}
scope
:created_after
,
->
(
date
)
{
where
(
scoped_table
[
:created_at
].
gteq
(
date
))
}
def
self
.
scoped_table
arel_table
.
alias
(
table_name
)
end
end
end
app/models/issue.rb
View file @
ad5e3798
...
...
@@ -10,6 +10,7 @@ class Issue < ActiveRecord::Base
include
FasterCacheKeys
include
RelativePositioning
include
IgnorableColumn
include
CreatedAtFilterable
ignore_column
:position
...
...
app/models/user.rb
View file @
ad5e3798
...
...
@@ -12,6 +12,7 @@ class User < ActiveRecord::Base
include
TokenAuthenticatable
include
IgnorableColumn
include
FeatureGate
include
CreatedAtFilterable
DEFAULT_NOTIFICATION_LEVEL
=
:participating
...
...
lib/gitlab/database/created_at_filter.rb
deleted
100644 → 0
View file @
d67a7ffe
module
Gitlab
module
Database
module
CreatedAtFilter
def
by_created_at
(
items
)
if
params
[
:created_after
].
present?
items
=
items
.
where
(
items
.
klass
.
arel_table
[
:created_at
].
gteq
(
params
[
:created_after
]))
end
if
params
[
:created_before
].
present?
items
=
items
.
where
(
items
.
klass
.
arel_table
[
:created_at
].
lteq
(
params
[
:created_before
]))
end
items
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment