From 75b6314e1dfc70cf53e716914b211664ee3dd768 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 18 Mar 2024 15:46:03 -0300 Subject: [PATCH] =?UTF-8?q?fix:=20qu=C3=A9=20pasa=20con=20los=20objetos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/activity_pub/fetch_job.rb | 7 ++++--- .../20240318183846_fix_duplicate_objects.rb | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20240318183846_fix_duplicate_objects.rb diff --git a/app/jobs/activity_pub/fetch_job.rb b/app/jobs/activity_pub/fetch_job.rb index 78a6dbee..f1a51e96 100644 --- a/app/jobs/activity_pub/fetch_job.rb +++ b/app/jobs/activity_pub/fetch_job.rb @@ -29,15 +29,16 @@ class ActivityPub current_type = object.type content = FastJsonparser.parse(response.body) - object.update(content: content, type: ActivityPub::Object.type_from(content).name) + object.update!(content: content, type: ActivityPub::Object.type_from(content).name) return if current_type == object.type object = ::ActivityPub::Object.find(object_id) - object.actor&.save if object.actor_type? + # Actualiza la mención + object.actor&.save! if object.actor_type? # Arreglar las relaciones con actividades también - ActivityPub.where(object_id: object.id).update_all(object_type: object.type) + ActivityPub.where(object_id: object.id).update_all(object_type: object.type, updated_at: Time.now) rescue FastJsonparser::ParseError => e ExceptionNotifier.notify_exception(e, data: { site: site.name, body: response.body }) end diff --git a/db/migrate/20240318183846_fix_duplicate_objects.rb b/db/migrate/20240318183846_fix_duplicate_objects.rb new file mode 100644 index 00000000..f863ba3e --- /dev/null +++ b/db/migrate/20240318183846_fix_duplicate_objects.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +# De alguna forma se guardaron objetos duplicados! +class FixDuplicateObjects < ActiveRecord::Migration[6.1] + def up + ActivityPub::Object.group(:uri).count.select { |_, v| v > 1 }.keys.each do |uri| + objects = ActivityPub::Object.where(uri: uri) + deleted_ids = objects[1..].map(&:delete).map(&:id) + + ActivityPub.where(object_id: deleted_ids).update_all(object_id: object.first.id, updated_at: Time.now) + end + end + + def down; end +end