Commit ff777213 authored by Peter Leitzen's avatar Peter Leitzen

Merge branch 'project/touch-updated_at' into 'master'

Project: update `updated_at` if `last_activity_at` or `last_repository_updated_at` are changed

See merge request gitlab-org/gitlab!78572
parents bbb673bf b21f9db2
......@@ -354,7 +354,7 @@ class Event < ApplicationRecord
# hence we add the extra WHERE clause for last_activity_at.
Project.unscoped.where(id: project_id)
.where('last_activity_at <= ?', RESET_PROJECT_ACTIVITY_INTERVAL.ago)
.update_all(last_activity_at: created_at)
.touch_all(:last_activity_at, time: created_at) # rubocop: disable Rails/SkipsModelValidations
end
def authored_by?(user)
......@@ -430,7 +430,7 @@ class Event < ApplicationRecord
def set_last_repository_updated_at
Project.unscoped.where(id: project_id)
.where("last_repository_updated_at < ? OR last_repository_updated_at IS NULL", REPOSITORY_UPDATED_AT_INTERVAL.ago)
.update_all(last_repository_updated_at: created_at)
.touch_all(:last_repository_updated_at, time: created_at) # rubocop: disable Rails/SkipsModelValidations
end
def design_action_names
......
......@@ -38,7 +38,7 @@ module Gitlab
# deliberate. If we were to update this column after the fetch we may
# miss out on changes pushed during the fetch or between the fetch and
# updating the timestamp.
project.update_column(:last_repository_updated_at, Time.zone.now)
project.touch(:last_repository_updated_at) # rubocop: disable Rails/SkipsModelValidations
project.repository.fetch_remote(project.import_url, refmap: Gitlab::GithubImport.refmap, forced: false)
......
......@@ -80,7 +80,7 @@ module Gitlab
end
def update_clone_time
project.update_column(:last_repository_updated_at, Time.zone.now)
project.touch(:last_repository_updated_at) # rubocop: disable Rails/SkipsModelValidations
end
private
......
......@@ -264,8 +264,8 @@ RSpec.describe Gitlab::GithubImport::Importer::RepositoryImporter do
it 'sets the timestamp for when the cloning process finished' do
freeze_time do
expect(project)
.to receive(:update_column)
.with(:last_repository_updated_at, Time.zone.now)
.to receive(:touch)
.with(:last_repository_updated_at)
importer.update_clone_time
end
......
......@@ -31,14 +31,15 @@ RSpec.describe Event do
describe 'after_create :set_last_repository_updated_at' do
context 'with a push event' do
it 'updates the project last_repository_updated_at' do
project.update!(last_repository_updated_at: 1.year.ago)
it 'updates the project last_repository_updated_at and updated_at' do
project.touch(:last_repository_updated_at, time: 1.year.ago) # rubocop: disable Rails/SkipsModelValidations
create_push_event(project, project.owner)
event = create_push_event(project, project.owner)
project.reload
expect(project.last_repository_updated_at).to be_within(1.minute).of(Time.current)
expect(project.last_repository_updated_at).to be_like_time(event.created_at)
expect(project.updated_at).to be_like_time(event.created_at)
end
end
......@@ -835,13 +836,14 @@ RSpec.describe Event do
context 'when a project was updated more than 1 hour ago' do
it 'updates the project' do
project.update!(last_activity_at: 1.year.ago)
project.touch(:last_activity_at, time: 1.year.ago) # rubocop: disable Rails/SkipsModelValidations
create_push_event(project, project.owner)
event = create_push_event(project, project.owner)
project.reload
expect(project.last_activity_at).to be_within(1.minute).of(Time.current)
expect(project.last_activity_at).to be_like_time(event.created_at)
expect(project.updated_at).to be_like_time(event.created_at)
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment