5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-29 15:16:21 +00:00

fix: qué pasa con los objetos

This commit is contained in:
f 2024-03-18 15:46:03 -03:00
parent e6d4b4d3f1
commit 75b6314e1d
No known key found for this signature in database
2 changed files with 19 additions and 3 deletions

View file

@ -29,15 +29,16 @@ class ActivityPub
current_type = object.type current_type = object.type
content = FastJsonparser.parse(response.body) 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 return if current_type == object.type
object = ::ActivityPub::Object.find(object_id) 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 # 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 rescue FastJsonparser::ParseError => e
ExceptionNotifier.notify_exception(e, data: { site: site.name, body: response.body }) ExceptionNotifier.notify_exception(e, data: { site: site.name, body: response.body })
end end

View file

@ -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