Clean up auto_sync code
parent
9697498b04
commit
4e677792c1
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue