Commit 33c8dfbd authored by Mike Kozono's avatar Mike Kozono

Refactor: Move needs_checksum? logic

into `should_primary_verify?`
parent 33acd0ea
......@@ -118,8 +118,9 @@ module Geo
end
end
# Schedules a verification job after a model record is created/updated
def after_verifiable_update
verify_async if needs_checksum?
verify_async if should_primary_verify?
end
def verify_async
......@@ -146,14 +147,7 @@ module Geo
# @param [String] checksum
# @return [Boolean] whether checksum matches
def matches_checksum?(checksum)
model_record.verification_checksum == checksum
end
def needs_checksum?
return false unless self.class.verification_enabled?
return true unless model_record.respond_to?(:needs_checksum?)
model_record.needs_checksum?
primary_checksum == checksum
end
# Checksum value from the main database
......@@ -170,5 +164,13 @@ module Geo
def verification_state_tracker
Gitlab::Geo.secondary? ? registry : model_record
end
private
def should_primary_verify?
self.class.verification_enabled? &&
primary_checksum.nil? && # Some models may populate this as part of creating the record
model_record.checksummable?
end
end
end
......@@ -57,17 +57,6 @@ module Gitlab
self.class.hexdigest(replicator.carrierwave_uploader.path)
end
# Checks whether model needs checksum to be performed
#
# Conditions:
# - No checksum is present
# - It's capable of generating a checksum of itself
#
# @return [Boolean]
def needs_checksum?
verification_checksum.nil? && checksummable?
end
# Return whether its capable of generating a checksum of itself
#
# @return [Boolean] whether it can generate a checksum
......
......@@ -299,8 +299,11 @@ RSpec.shared_examples 'a verifiable replicator' do
describe '#after_verifiable_update' do
it 'calls verify_async if needed' do
allow(described_class).to receive(:verification_enabled?).and_return(true)
allow(replicator).to receive(:primary_checksum).and_return(nil)
allow(model_record).to receive(:checksummable?).and_return(true)
expect(replicator).to receive(:verify_async)
expect(replicator).to receive(:needs_checksum?).and_return(true)
replicator.after_verifiable_update
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