Commit a855aade authored by Alejandro Rodríguez's avatar Alejandro Rodríguez

Reduce UPDATE queries when moving between import states on projects

By changing our logic from `before_transition` to `after_transition`
blocks and removing extra calls to `update` or `save` we can do all
changes in a single UPDATE query (currently each transition change
from started -> failed and started -> finished runs two UPDATE
queries each)
parent 361b3a43
Please view this file on the master branch, on stable branches it's out of date.
v 8.12.0 (Unreleased)
- Reduce UPDATE queries when moving between import states on projects
- [ES] Instrument Elasticsearch::Git::Repository
- [ES] Instrument other Gitlab::Elastic classes
......
......@@ -237,12 +237,11 @@ class Project < ActiveRecord::Base
after_transition any => :finished, do: :reset_cache_and_import_attrs
after_transition started: :finished do |project, transaction|
before_transition started: :finished do |project, transaction|
if project.mirror?
timestamp = DateTime.now
project.mirror_last_update_at = timestamp
project.mirror_last_successful_update_at = timestamp
project.save
end
if current_application_settings.elasticsearch_indexing?
......@@ -250,10 +249,8 @@ class Project < ActiveRecord::Base
end
end
after_transition started: :failed do |project, transaction|
if project.mirror?
project.update(mirror_last_update_at: DateTime.now)
end
before_transition started: :failed do |project, transaction|
project.mirror_last_update_at = DateTime.now if project.mirror?
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