Skip trying to match editions

It's rare that it will be useful, and it was a huge hassle.
This commit is contained in:
Mouse Reeve 2023-07-18 19:33:02 -07:00
parent 8b88de624d
commit ccf3a4c5c1
3 changed files with 6 additions and 24 deletions

View file

@ -126,18 +126,6 @@ class ActivitypubMixin:
# there OUGHT to be only one match
return match.first()
def get_dedpulication_field_json(self):
"""A json blob of deduplication fields (like remote_id, or ISBN)"""
data = {}
for field in self._meta.get_fields():
if (
not hasattr(field, "deduplication_field")
or not field.deduplication_field
):
continue
data[field.name] = getattr(self, field.name)
return data
def broadcast(self, activity, sender, software=None, queue=BROADCAST):
"""send out an activity"""
broadcast_task.apply_async(

View file

@ -2,7 +2,6 @@
from itertools import chain
import re
from django.apps import apps
from django.contrib.postgres.search import SearchVectorField
from django.contrib.postgres.indexes import GinIndex
from django.core.cache import cache
@ -381,22 +380,16 @@ class Edition(Book):
return super().save(*args, **kwargs)
@transaction.atomic
def repair(self):
"""If an edition is in a bad state (missing a work), let's fix that"""
# made sure it actually NEEDS reapir
if self.parent_work:
return
# try to find a duplicate of this edition first
model = apps.get_model("bookwyrm.Edition", require_ready=True)
data = self.get_dedpulication_field_json()
existing_match = model.find_existing(data)
# assign this edition to the parent of the duplicate edition
if existing_match and existing_match.parent_work:
new_work = existing_match.parent_work
else:
new_work = Work.objects.create(title=self.title)
new_work = Work.objects.create(title=self.title)
new_work.authors.set(self.authors.all())
self.parent_work = new_work
self.save(update_fields=["parent_work"], broadcast=False)

View file

@ -24,8 +24,7 @@ class Book(TestCase):
title="Example Work", remote_id="https://example.com/book/1"
)
self.first_edition = models.Edition.objects.create(
title="Example Edition",
parent_work=self.work,
title="Example Edition", parent_work=self.work, isbn_10="1111111111"
)
self.second_edition = models.Edition.objects.create(
title="Another Example Edition",
@ -147,9 +146,11 @@ class Book(TestCase):
def test_repair_edition(self):
"""Fix editions with no works"""
edition = models.Edition.objects.create(title="test")
edition.authors.set([models.Author.objects.create(name="Author Name")])
self.assertIsNone(edition.parent_work)
edition.repair()
edition.refresh_from_db()
self.assertEqual(edition.parent_work.title, "test")
self.assertEqual(edition.parent_work.authors.count(), 1)