lib/table_sync/receiving/handler.rb in table_sync-4.0.0 vs lib/table_sync/receiving/handler.rb in table_sync-4.1.0

- old
+ new

@@ -107,25 +107,26 @@ def perform(config, params) model = config.model model.transaction do - if event == :update - config.before_update(**params) + results = if event == :update + config.before_update(**params) + model.upsert(**params) + else + config.before_destroy(**params) + model.destroy(**params) + end - results = model.upsert(**params) + model.after_commit do + TableSync::Instrument.notify table: model.table, schema: model.schema, + count: results.count, event: event, direction: :receive + end - model.after_commit do - config.after_commit_on_update(**params.merge(results: results)) - end + if event == :update + model.after_commit { config.after_commit_on_update(**params.merge(results: results)) } else - config.before_destroy(**params) - - results = model.destroy(**params) - - model.after_commit do - config.after_commit_on_destroy(**params.merge(results: results)) - end + model.after_commit { config.after_commit_on_destroy(**params.merge(results: results)) } end end end end