fix soft-deleted item and discover page
This commit is contained in:
parent
092d890ddc
commit
cdd9ff55d6
6 changed files with 52 additions and 1 deletions
catalog
journal/migrations
users/migrations
|
@ -271,7 +271,7 @@ class Edition(Item):
|
|||
def delete(self, using=None, keep_parents=False, soft=True, *args, **kwargs):
|
||||
if soft:
|
||||
self.works.clear()
|
||||
return super().delete(using, soft, keep_parents, *args, **kwargs)
|
||||
return super().delete(using, keep_parents, soft, *args, **kwargs)
|
||||
|
||||
def update_linked_items_from_external_resource(self, resource):
|
||||
"""add Work from resource.metadata['work'] if not yet"""
|
||||
|
|
16
catalog/common/migrations.py
Normal file
16
catalog/common/migrations.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
from django.db import connection
|
||||
from loguru import logger
|
||||
|
||||
|
||||
def fix_20250208():
|
||||
logger.warning("Fixing soft-deleted editions...")
|
||||
with connection.cursor() as cursor:
|
||||
cursor.execute("""
|
||||
UPDATE catalog_item
|
||||
SET is_deleted = true
|
||||
WHERE id NOT IN ( SELECT item_ptr_id FROM catalog_edition ) AND polymorphic_ctype_id = (SELECT id FROM django_content_type WHERE app_label='catalog' AND model='edition');
|
||||
INSERT INTO catalog_edition (item_ptr_id)
|
||||
SELECT id FROM catalog_item
|
||||
WHERE id NOT IN ( SELECT item_ptr_id FROM catalog_edition ) AND polymorphic_ctype_id = (SELECT id FROM django_content_type WHERE app_label='catalog' AND model='edition');
|
||||
""")
|
||||
logger.warning("Fix complete.")
|
|
@ -111,6 +111,7 @@ class DiscoverGenerator(BaseJob):
|
|||
)
|
||||
item_ids = extra_ids + item_ids
|
||||
items = [Item.objects.get(pk=i) for i in item_ids]
|
||||
items = [i for i in items if not i.is_deleted and not i.merged_to_item_id]
|
||||
if category == ItemCategory.TV:
|
||||
items = self.cleanup_shows(items)
|
||||
key = "trending_" + category.value
|
||||
|
|
23
catalog/migrations/0002_fix_soft_deleted_edition.py
Normal file
23
catalog/migrations/0002_fix_soft_deleted_edition.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
# Generated by Django 4.2.18 on 2025-02-09 02:40
|
||||
|
||||
import django_rq
|
||||
from django.db import migrations
|
||||
|
||||
from catalog.common.migrations import fix_20250208
|
||||
|
||||
|
||||
# this is a fix for a bug introduced in 0.10
|
||||
# safe to be excluded in squashed migration in future
|
||||
def fix_soft_deleted_edition(apps, schema_editor):
|
||||
django_rq.get_queue("mastodon").enqueue(fix_20250208)
|
||||
print("(Queued)", end="")
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("catalog", "0001_initial_0_10"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(fix_soft_deleted_edition),
|
||||
]
|
|
@ -20,4 +20,14 @@ class Migration(migrations.Migration):
|
|||
},
|
||||
bases=("users.task",),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name="NdjsonExporter",
|
||||
fields=[],
|
||||
options={
|
||||
"proxy": True,
|
||||
"indexes": [],
|
||||
"constraints": [],
|
||||
},
|
||||
bases=("users.task",),
|
||||
),
|
||||
]
|
||||
|
|
|
@ -19,6 +19,7 @@ class Migration(migrations.Migration):
|
|||
("journal.doufenexporter", "doufen exporter"),
|
||||
("journal.goodreadsimporter", "goodreads importer"),
|
||||
("journal.letterboxdimporter", "letterboxd importer"),
|
||||
("journal.ndjsonexporter", "ndjson exporter"),
|
||||
],
|
||||
db_index=True,
|
||||
max_length=255,
|
||||
|
|
Loading…
Add table
Reference in a new issue