Clean up auto_sync code

pull/1492/head
Rick Carlino 2019-10-07 14:14:59 -05:00
parent 9697498b04
commit 4e677792c1
3 changed files with 8 additions and 9 deletions

View File

@ -44,9 +44,10 @@ class ApplicationRecord < ActiveRecord::Base
end
def broadcast?
!self.class.auto_sync_paused &&
current_device &&
(gone? || notable_changes?)
return false if self.class.auto_sync_paused
return false unless current_device
return false unless (gone? || notable_changes?)
return true
end
def maybe_broadcast
@ -91,9 +92,9 @@ class ApplicationRecord < ActiveRecord::Base
end
def manually_sync!
device.auto_sync_transaction do
device && (device.auto_sync_transaction do
update_attributes!(updated_at: Time.now)
end if device
end)
self
end
end

View File

@ -3,6 +3,7 @@ class PointGroup < ApplicationRecord
%w(xy_ascending xy_descending yx_ascending yx_descending random).sort
BAD_SORT = "%{value} is not valid. Valid options are: " +
SORT_TYPES.map(&:inspect).join(", ")
DONT_BROADCAST = ApplicationRecord::DONT_BROADCAST.without("updated_at")
belongs_to :device
has_many :point_group_items, dependent: :destroy

View File

@ -65,10 +65,7 @@ module Points
# Cache relations *before* deleting PGIs.
pgs = point_groups
point_group_items.destroy_all
pgs.map do |pg|
puts "Manually syncing #{pg.name}"
pg.manually_sync!
end
pgs.map(&:manually_sync!)
end
def points