summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2018-03-03 05:59:40 -0800
committerStan Hu <stanhu@gmail.com>2018-03-05 19:11:50 -0800
commit9cb7e93f09b1ff0c1c889a004479a8ef21abbae2 (patch)
tree00a0c5f114a481b19de02767ebba16fb9521c474
parent8a0052c037f025b64159ca8cfe0d3451261c1edb (diff)
downloadgitlab-ce-sh-dashboard-sort-fix.tar.gz
Fix project dashboard showing the wrong timestampssh-dashboard-sort-fix
Use the max of the `last_activity_at` and `last_repository_updated_at` columns. The latter is updated only when a push happens, but the former is updated whenever any activity (e.g. issue creation) happens. Closes #27181
-rw-r--r--app/models/project.rb5
-rw-r--r--changelogs/unreleased/sh-dashboard-sort-fix.yml5
-rw-r--r--spec/features/dashboard/projects_spec.rb8
-rw-r--r--spec/models/project_spec.rb14
4 files changed, 30 insertions, 2 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index 5b1f8b2658b..099eaa53d23 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -274,7 +274,8 @@ class Project < ActiveRecord::Base
scope :without_storage_feature, ->(feature) { where('storage_version < :version OR storage_version IS NULL', version: HASHED_STORAGE_FEATURES[feature]) }
scope :with_unmigrated_storage, -> { where('storage_version < :version OR storage_version IS NULL', version: LATEST_STORAGE_VERSION) }
- scope :sorted_by_activity, -> { reorder(last_activity_at: :desc) }
+ # last_activity_at is throttled every minute, but last_repository_updated_at is updated with every push
+ scope :sorted_by_activity, -> { reorder("GREATEST(COALESCE(last_activity_at, '1970-01-01'), COALESCE(last_repository_updated_at, '1970-01-01')) DESC") }
scope :sorted_by_stars, -> { reorder('projects.star_count DESC') }
scope :in_namespace, ->(namespace_ids) { where(namespace_id: namespace_ids) }
@@ -776,7 +777,7 @@ class Project < ActiveRecord::Base
end
def last_activity_date
- last_repository_updated_at || last_activity_at || updated_at
+ [last_activity_at, last_repository_updated_at, updated_at].compact.max
end
def project_id
diff --git a/changelogs/unreleased/sh-dashboard-sort-fix.yml b/changelogs/unreleased/sh-dashboard-sort-fix.yml
new file mode 100644
index 00000000000..6fd252f6707
--- /dev/null
+++ b/changelogs/unreleased/sh-dashboard-sort-fix.yml
@@ -0,0 +1,5 @@
+---
+title: Fix project dashboard showing the wrong timestamps
+merge_request:
+author:
+type: fixed
diff --git a/spec/features/dashboard/projects_spec.rb b/spec/features/dashboard/projects_spec.rb
index 586c7b48d0b..986f864f0b5 100644
--- a/spec/features/dashboard/projects_spec.rb
+++ b/spec/features/dashboard/projects_spec.rb
@@ -37,6 +37,14 @@ feature 'Dashboard Projects' do
expect(page).to have_xpath("//time[@datetime='#{project.last_repository_updated_at.getutc.iso8601}']")
end
+
+ it 'shows the last_activity_at attribute as the update date' do
+ project.update_attributes!(last_repository_updated_at: 1.hour.ago, last_activity_at: Time.now)
+
+ visit dashboard_projects_path
+
+ expect(page).to have_xpath("//time[@datetime='#{project.last_activity_at.getutc.iso8601}']")
+ end
end
context 'when last_repository_updated_at and last_activity_at are missing' do
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index f4faec9e52a..27bb1a2e3bd 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -517,6 +517,20 @@ describe Project do
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_attributes(updated_at: nil,
+ last_activity_at: timestamp,
+ last_repository_updated_at: timestamp - 1.hour)
+
+ expect(project.last_activity_date).to eq(timestamp)
+
+ project.update_attributes(updated_at: timestamp,
+ last_activity_at: timestamp - 1.hour,
+ last_repository_updated_at: nil)
+
+ expect(project.last_activity_date).to eq(timestamp)
+ end
end
end