Skip to content
Snippets Groups Projects
Unverified Commit 1966d4e9 authored by Sébastien Gaya's avatar Sébastien Gaya
Browse files

early return in syncs

parent 890359c0
No related branches found
No related tags found
No related merge requests found
......@@ -50,7 +50,7 @@ class Communication::Website::Imported::Page < ApplicationRecord
optional: true
before_validation :sync
after_save :sync_attachments
after_commit :sync_attachments, on: [:create, :update]
default_scope { order(:path) }
......@@ -84,7 +84,7 @@ class Communication::Website::Imported::Page < ApplicationRecord
# Continue only if there are remote changes
# Don't touch if there are local changes (page.updated_at > updated_at)
# Don't touch if there are no remote changes (page.updated_at == updated_at)
# return unless updated_at > page.updated_at
return unless updated_at > page.updated_at
end
puts "Update page #{page.id}"
sanitized_title = Wordpress.clean_string self.title.to_s
......@@ -97,6 +97,7 @@ class Communication::Website::Imported::Page < ApplicationRecord
end
def sync_attachments
return unless updated_at > page.updated_at
if featured_medium.present?
unless featured_medium.file.attached? && featured_medium.file.blob.persisted?
featured_medium.load_remote_file!
......
......@@ -48,7 +48,7 @@ class Communication::Website::Imported::Post < ApplicationRecord
optional: true
before_validation :sync
after_save :sync_attachments
after_commit :sync_attachments, on: [:create, :update]
default_scope { order(path: :desc) }
......@@ -82,7 +82,7 @@ class Communication::Website::Imported::Post < ApplicationRecord
# Continue only if there are remote changes
# Don't touch if there are local changes (post.updated_at > updated_at)
# Don't touch if there are no remote changes (post.updated_at == updated_at)
# return unless updated_at > post.updated_at
return unless updated_at > post.updated_at
end
puts "Update post #{post.id}"
sanitized_title = Wordpress.clean_string self.title.to_s
......@@ -98,6 +98,7 @@ class Communication::Website::Imported::Post < ApplicationRecord
end
def sync_attachments
return unless updated_at > post.updated_at
if featured_medium.present?
unless featured_medium.file.attached? && featured_medium.file.blob.persisted?
featured_medium.load_remote_file!
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment