diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2024-06-07 17:41:03 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2024-06-07 17:42:56 +0200 |
commit | 0d585824a02b3f7133e323d72bd1e778f9fa12ea (patch) | |
tree | 5963b99db4e79f28d4f4603074906b01c7c10efa | |
parent | 26ba00071ad1eb8b5bd3479290b6ffe02101298d (diff) | |
download | Ishtar-0d585824a02b3f7133e323d72bd1e778f9fa12ea.tar.bz2 Ishtar-0d585824a02b3f7133e323d72bd1e778f9fa12ea.zip |
🗃️ Document: add cache_authors field (refs #5709)
-rw-r--r-- | ishtar_common/migrations/0247_document_cached_authors.py | 37 | ||||
-rw-r--r-- | ishtar_common/models.py | 15 |
2 files changed, 49 insertions, 3 deletions
diff --git a/ishtar_common/migrations/0247_document_cached_authors.py b/ishtar_common/migrations/0247_document_cached_authors.py new file mode 100644 index 000000000..862dc036b --- /dev/null +++ b/ishtar_common/migrations/0247_document_cached_authors.py @@ -0,0 +1,37 @@ +# Generated by Django 2.2.24 on 2024-06-07 17:22 + +from django.db import migrations, models + + +def generate_cache_authors(apps, __): + Document = apps.get_model('ishtar_common', 'Document') + for doc in Document.objects.all(): + doc.cache_authors = " ; ".join([author.cached_label for author in doc.authors.all()]) + doc.skip_history_when_saving = True + doc.no_post_process() + doc.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('ishtar_common', '0246_profile_rel_engine_default_changed_to_cache_tables'), + ] + + operations = [ + migrations.AlterModelOptions( + name='jsondatasection', + options={'ordering': ['order', 'name'], 'verbose_name': 'Custom data - Section', 'verbose_name_plural': 'Custom data - Sections'}, + ), + migrations.AddField( + model_name='document', + name='cache_authors', + field=models.TextField(blank=True, db_index=True, default='', help_text='Cached value - do not edit', verbose_name='Authors'), + ), + migrations.AddField( + model_name='historicaldocument', + name='cache_authors', + field=models.TextField(blank=True, db_index=True, default='', help_text='Cached value - do not edit', verbose_name='Authors'), + ), + migrations.RunPython(generate_cache_authors) + ] diff --git a/ishtar_common/models.py b/ishtar_common/models.py index c098eee02..ed7df17c2 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -4229,7 +4229,7 @@ class Document( "title", "source_type__label", "cache_related_label", - "authors__cached_label", + "cache_authors", "associated_url", ] NEW_QUERY_ENGINE = True @@ -4273,7 +4273,7 @@ class Document( "source_type__label": _("Type"), } - CACHED_LABELS = ["cache_related_label"] + CACHED_LABELS = ["cache_related_label", "cache_authors"] CACHED_COMPLETE_ID = "" EXTRA_REQUEST_KEYS = { "operations": "operations__pk", @@ -4568,7 +4568,6 @@ class Document( ] SERIALIZATION_FILES = ["image", "thumbnail", "associated_file"] SERIALIZE_PROPERTIES = ["external_id", "images_number"] - SELECT_GROUP_BY = True # v4.0 patch title = models.TextField(_("Title"), blank=True, default="") associated_file = models.FileField( @@ -4709,6 +4708,13 @@ class Document( db_index=True, help_text=_("Cached value - do not edit"), ) + cache_authors = models.TextField( + _("Authors"), + blank=True, + default="", + db_index=True, + help_text=_("Cached value - do not edit"), + ) history = HistoricalRecords(inherit=True) class Meta: @@ -5135,6 +5141,9 @@ class Document( def _generate_cache_related_label(self): return self.related_label()[:1000] + def _generate_cache_authors(self): + return " ; ".join([author.cached_label for author in self.authors.all()]) + @classmethod def get_next_index(cls): q = cls.objects.values("index").filter(index__isnull=False).order_by("-index") |