summaryrefslogtreecommitdiff
path: root/archaeological_context_records/models.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2023-11-13 17:35:16 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2023-11-13 18:07:57 +0100
commit1d1fd6c794c8ca8e758fc416b43e0f881136057f (patch)
treede87e065216f4d1302893c9bd8c2e8b1430b1eea /archaeological_context_records/models.py
parentc5b1321e8c1960e75ecf309a8df471dbe53548a2 (diff)
downloadIshtar-1d1fd6c794c8ca8e758fc416b43e0f881136057f.tar.bz2
Ishtar-1d1fd6c794c8ca8e758fc416b43e0f881136057f.zip
⚡️ remove bulk update: should not be useful anymore and can severely degrade performance
Diffstat (limited to 'archaeological_context_records/models.py')
-rw-r--r--archaeological_context_records/models.py92
1 files changed, 0 insertions, 92 deletions
diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py
index eb786db74..985390861 100644
--- a/archaeological_context_records/models.py
+++ b/archaeological_context_records/models.py
@@ -999,94 +999,6 @@ class ContextRecord(
}
return dct
- @classmethod
- def cached_label_bulk_update(
- cls, operation_id=None, parcel_id=None, transaction_id=None
- ):
- profile = get_current_profile()
- if profile.contextrecord_cached_label:
- # no bulk possible
- q = cls.objects
- if operation_id:
- q = q.filter(operation_id=operation_id)
- elif parcel_id:
- q = q.filter(parcel_id=parcel_id)
- else:
- return
- for cr in q.all():
- cr.skip_history_when_saving = True
- cr._no_move = True
- cr.save()
- cls._meta.get_field("base_finds").related_model.cached_label_bulk_update(
- operation_id=operation_id, parcel_id=parcel_id,
- transaction_id=transaction_id
- )
- return
- transaction_id, is_recursion = cls.bulk_recursion(
- transaction_id, [operation_id, parcel_id]
- )
- if is_recursion:
- return
-
- if operation_id:
- where = "operation_id = %s"
- args = [int(operation_id)]
- kwargs = {"operation_id": operation_id}
- elif parcel_id:
- where = "parcel_id = %s"
- args = [int(parcel_id)]
- kwargs = {"parcel_id": parcel_id}
- else:
- return
- kwargs["transaction_id"] = transaction_id
-
- profile = get_current_profile()
-
- sql = """
- UPDATE "archaeological_context_records_contextrecord" AS cr
- SET cached_label =
- CASE
- WHEN context_records_cached_label_bulk_update.main_code
- IS NULL
- THEN
- CASE
- WHEN context_records_cached_label_bulk_update.year
- IS NOT NULL
- AND context_records_cached_label_bulk_update.ope_code
- IS NOT NULL
- THEN
- '{ope_prefix}' ||
- context_records_cached_label_bulk_update.year ||
- '-' ||
- context_records_cached_label_bulk_update.ope_code
- ELSE ''
- END
- ELSE
- '{main_ope_prefix}' ||
- context_records_cached_label_bulk_update.main_code
- END
- || '{join}' ||
- context_records_cached_label_bulk_update.section || '{join}' ||
- context_records_cached_label_bulk_update.number || '{join}' ||
- context_records_cached_label_bulk_update.label
- FROM context_records_cached_label_bulk_update
- WHERE cr.id = context_records_cached_label_bulk_update.id
- AND cr.id IN (
- SELECT id FROM archaeological_context_records_contextrecord
- WHERE {where}
- );
- """.format(
- main_ope_prefix=(profile.operation_prefix or ""),
- ope_prefix=(profile.default_operation_prefix or ""),
- join=settings.JOINT,
- where=where,
- )
- with connection.cursor() as c:
- c.execute(sql, args)
- cls._meta.get_field("base_finds").related_model.cached_label_bulk_update(
- **kwargs
- )
-
@property
def short_label(self):
return settings.JOINT.join(
@@ -1230,10 +1142,6 @@ class ContextRecord(
BaseFind.objects.filter(context_record=self).all()
)
- def _cached_labels_bulk_update(self):
- self.base_finds.model.cached_label_bulk_update(context_record_id=self.pk)
- return True
-
def _get_base_image_path(self):
return self.operation._get_base_image_path() + "/{}/{}".format(
self.SLUG, slugify(self.label or "00")