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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
df508685
Commit
df508685
authored
Mar 24, 2022
by
Jonas Wälter
Committed by
Peter Leitzen
Mar 24, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Order projects by real last update
Changelog: changed
parent
e7983f2e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
33 deletions
+24
-33
app/controllers/dashboard/application_controller.rb
app/controllers/dashboard/application_controller.rb
+1
-1
app/models/project.rb
app/models/project.rb
+5
-5
spec/models/project_spec.rb
spec/models/project_spec.rb
+18
-27
No files found.
app/controllers/dashboard/application_controller.rb
View file @
df508685
...
...
@@ -11,6 +11,6 @@ class Dashboard::ApplicationController < ApplicationController
private
def
projects
@projects
||=
current_user
.
authorized_projects
.
sorted_by_
activity
.
non_archived
@projects
||=
current_user
.
authorized_projects
.
sorted_by_
updated_desc
.
non_archived
end
end
app/models/project.rb
View file @
df508685
...
...
@@ -546,8 +546,8 @@ class Project < ApplicationRecord
.
or
(
arel_table
[
:storage_version
].
eq
(
nil
)))
end
# last_activity_at is throttled every minute, but last_repository_updated_at is updated with every push
scope
:sorted_by_
activity
,
->
{
reorder
(
Arel
.
sql
(
"GREATEST(COALESCE(last_activity_at, '1970-01-01'), COALESCE(last_repository_updated_at, '1970-01-01')) DESC"
)
)
}
scope
:sorted_by_updated_asc
,
->
{
reorder
(
self
.
arel_table
[
'updated_at'
].
asc
)
}
scope
:sorted_by_
updated_desc
,
->
{
reorder
(
self
.
arel_table
[
'updated_at'
].
desc
)
}
scope
:sorted_by_stars_desc
,
->
{
reorder
(
self
.
arel_table
[
'star_count'
].
desc
)
}
scope
:sorted_by_stars_asc
,
->
{
reorder
(
self
.
arel_table
[
'star_count'
].
asc
)
}
# Sometimes queries (e.g. using CTEs) require explicit disambiguation with table name
...
...
@@ -783,9 +783,9 @@ class Project < ApplicationRecord
# pass a string to avoid AR adding the table name
reorder
(
'project_statistics.storage_size DESC, projects.id DESC'
)
when
'latest_activity_desc'
reorder
(
self
.
arel_table
[
'last_activity_at'
].
desc
)
sorted_by_updated_desc
when
'latest_activity_asc'
reorder
(
self
.
arel_table
[
'last_activity_at'
].
asc
)
sorted_by_updated_asc
when
'stars_desc'
sorted_by_stars_desc
when
'stars_asc'
...
...
@@ -1404,7 +1404,7 @@ class Project < ApplicationRecord
end
def
last_activity_date
[
last_activity_at
,
last_repository_updated_at
,
updated_at
].
compact
.
max
updated_at
end
def
project_id
...
...
spec/models/project_spec.rb
View file @
df508685
...
...
@@ -1191,29 +1191,8 @@ RSpec.describe Project, factory_default: :keep do
end
describe
'last_activity_date'
do
it
'returns the creation date of the project\'s last event if present'
do
new_event
=
create
(
:event
,
:closed
,
project:
project
,
created_at:
Time
.
current
)
project
.
reload
expect
(
project
.
last_activity_at
.
to_i
).
to
eq
(
new_event
.
created_at
.
to_i
)
end
it
'returns the project\'s last update date if it has no events'
do
expect
(
project
.
last_activity_date
).
to
eq
(
project
.
updated_at
)
end
it
'returns the most recent timestamp'
do
project
.
update!
(
updated_at:
nil
,
last_activity_at:
timestamp
,
last_repository_updated_at:
timestamp
-
1
.
hour
)
expect
(
project
.
last_activity_date
).
to
be_like_time
(
timestamp
)
project
.
update!
(
updated_at:
timestamp
,
last_activity_at:
timestamp
-
1
.
hour
,
last_repository_updated_at:
nil
)
expect
(
project
.
last_activity_date
).
to
be_like_time
(
timestamp
)
it
'returns the project\'s last update date'
do
expect
(
project
.
last_activity_date
).
to
be_like_time
(
project
.
updated_at
)
end
end
end
...
...
@@ -1690,15 +1669,27 @@ RSpec.describe Project, factory_default: :keep do
end
describe
'.sort_by_attribute'
do
it
'reorders the input relation by start count desc'
do
project1
=
create
(
:project
,
star_count:
2
)
project2
=
create
(
:project
,
star_count:
1
)
project3
=
create
(
:project
)
let_it_be
(
:project1
)
{
create
(
:project
,
star_count:
2
,
updated_at:
1
.
minute
.
ago
)
}
let_it_be
(
:project2
)
{
create
(
:project
,
star_count:
1
)
}
let_it_be
(
:project3
)
{
create
(
:project
,
updated_at:
2
.
minutes
.
ago
)
}
it
'reorders the input relation by start count desc'
do
projects
=
described_class
.
sort_by_attribute
(
:stars_desc
)
expect
(
projects
).
to
eq
([
project1
,
project2
,
project3
])
end
it
'reorders the input relation by last activity desc'
do
projects
=
described_class
.
sort_by_attribute
(
:latest_activity_desc
)
expect
(
projects
).
to
eq
([
project2
,
project1
,
project3
])
end
it
'reorders the input relation by last activity asc'
do
projects
=
described_class
.
sort_by_attribute
(
:latest_activity_asc
)
expect
(
projects
).
to
eq
([
project3
,
project1
,
project2
])
end
end
describe
'.with_shared_runners'
do
...
...
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