Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
cda7cbde
Commit
cda7cbde
authored
Jul 07, 2017
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor created at filter to use model scopes
parent
5e66c656
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
25 additions
and
20 deletions
+25
-20
app/finders/created_at_filter.rb
app/finders/created_at_filter.rb
+8
-0
app/finders/issuable_finder.rb
app/finders/issuable_finder.rb
+2
-2
app/finders/users_finder.rb
app/finders/users_finder.rb
+1
-1
app/models/concerns/created_at_filterable.rb
app/models/concerns/created_at_filterable.rb
+12
-0
app/models/issue.rb
app/models/issue.rb
+1
-0
app/models/user.rb
app/models/user.rb
+1
-0
lib/gitlab/database/created_at_filter.rb
lib/gitlab/database/created_at_filter.rb
+0
-17
No files found.
app/finders/created_at_filter.rb
0 → 100644
View file @
cda7cbde
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 @
cda7cbde
...
...
@@ -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
)
...
...
app/finders/users_finder.rb
View file @
cda7cbde
...
...
@@ -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 @
cda7cbde
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 @
cda7cbde
...
...
@@ -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 @
cda7cbde
...
...
@@ -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 @
5e66c656
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