summaryrefslogtreecommitdiff
path: root/ishtar_common
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2025-06-26 20:45:11 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2025-06-27 10:59:30 +0200
commit66f6d4951bc7cd801757feca3b4a403ebedb2d64 (patch)
tree09ffe42906a9a6492a102efd0240aaaf93bd8943 /ishtar_common
parent42b0ad69ed32fb72787e3bcdd0400ec7e2eb9156 (diff)
downloadIshtar-66f6d4951bc7cd801757feca3b4a403ebedb2d64.tar.bz2
Ishtar-66f6d4951bc7cd801757feca3b4a403ebedb2d64.zip
⚡️ imports: performance optimisations
Diffstat (limited to 'ishtar_common')
-rw-r--r--ishtar_common/data_importer.py19
-rw-r--r--ishtar_common/models_common.py22
-rw-r--r--ishtar_common/wizards.py2
3 files changed, 33 insertions, 10 deletions
diff --git a/ishtar_common/data_importer.py b/ishtar_common/data_importer.py
index 9d470a084..9329fbfac 100644
--- a/ishtar_common/data_importer.py
+++ b/ishtar_common/data_importer.py
@@ -945,6 +945,8 @@ class Importer(object):
item = cls.objects.get(pk=pk)
except cls.DoesNotExist:
continue
+ if cls != self.OBJECT_CLS:
+ cls._no_down_model_update = True
item._timestamp = self.timestamp
item._queue = "low_priority"
item.save()
@@ -1186,6 +1188,8 @@ class Importer(object):
def _create_item(self, cls, dct, idx_line):
obj = cls(**dct)
obj._no_post_save = True # delayed at the end of the import
+ if hasattr(obj, "no_post_process"):
+ obj.no_post_process(history=True)
obj._queue = "low_priority"
obj.save()
self._add_to_post_save(cls, obj.pk, idx_line)
@@ -1329,6 +1333,9 @@ class Importer(object):
else:
self.number_updated += 1
+ if hasattr(obj, "no_post_process"):
+ obj.no_post_process(history=True)
+
if not created and "defaults" in data:
for k in data["defaults"]:
setattr(obj, k, data["defaults"][k])
@@ -1375,6 +1382,8 @@ class Importer(object):
setattr(item, k, geodata[k])
item._timestamp = self.timestamp
item._queue = "low_priority"
+ if hasattr(item, "no_post_process"):
+ item.no_post_process(history=True)
item.save()
else:
item = GeoVectorData.objects.create(**geodata)
@@ -1393,6 +1402,8 @@ class Importer(object):
obj._no_move = True
obj.skip_history_when_saving = True
obj._queue = "low_priority"
+ if hasattr(obj, "no_post_process"):
+ obj.no_post_process(history=True)
obj.save()
n = datetime.datetime.now()
@@ -1466,6 +1477,8 @@ class Importer(object):
t_obj._no_post_save = True
t_obj._timestamp = self.timestamp
t_obj._queue = "low_priority"
+ if hasattr(t_obj, "no_post_process"):
+ t_obj.no_post_process(history=True)
t_obj.save()
self._add_to_post_save(t_obj.__class__, t_obj.pk, idx_line)
if self.import_instance and hasattr(t_obj, "imports") and created:
@@ -1808,6 +1821,8 @@ class Importer(object):
if changed:
v._timestamp = self.timestamp
v._queue = "low_priority"
+ if hasattr(v, "no_post_process"):
+ v.no_post_process(history=True)
v.save()
for att, objs in m2m_m2ms:
if type(objs) not in (list, tuple):
@@ -2157,6 +2172,8 @@ class Importer(object):
setattr(obj, k, updated_dct[k])
obj._timestamp = self.timestamp
obj._queue = "low_priority"
+ if hasattr(obj, "no_post_process"):
+ obj.no_post_process(history=True)
obj.save()
if (
not self.simulate
@@ -2227,6 +2244,8 @@ class Importer(object):
try:
v._timestamp = self.timestamp
v._queue = "low_priority"
+ if hasattr(v, "no_post_process"):
+ v.no_post_process(history=True)
v.save()
except DatabaseError as import_error:
msg = str(import_error)
diff --git a/ishtar_common/models_common.py b/ishtar_common/models_common.py
index e749580f4..19d04ea17 100644
--- a/ishtar_common/models_common.py
+++ b/ishtar_common/models_common.py
@@ -1133,7 +1133,8 @@ class FullSearch(models.Model):
m2m_search_vector.key, config=m2m_search_vector.language
)
).values("search")
- search_vectors.append(q.all()[0]["search"])
+ if q.count():
+ search_vectors.append(q.all()[0]["search"])
# int/float are not well managed by the SearchVector
for int_search_vector in self.INT_SEARCH_VECTORS:
@@ -1950,6 +1951,16 @@ class BaseHistorizedItem(
self.fix_associated()
return True
+ def no_post_process(self, history=False):
+ if not history:
+ self.skip_history_when_saving = True
+ self._cached_label_checked = True
+ self._post_saved_geo = True
+ self._external_id_checked = True
+ self._search_updated = True
+ self._no_move = True
+ self._no_down_model_update = True
+
class LightHistorizedItem(BaseHistorizedItem):
history_date = models.DateTimeField(default=datetime.datetime.now)
@@ -3440,15 +3451,6 @@ class MainItem(ShortMenuItem, SerializeItem, SheetItem):
if hasattr(item, "main_geodata"):
item.post_save_geo()
- def no_post_process(self):
- self.skip_history_when_saving = True
- self._cached_label_checked = True
- self._post_saved_geo = True
- self._external_id_checked = True
- self._search_updated = True
- self._no_move = True
- self._no_down_model_update = True
-
@classmethod
def app_label(cls):
return cls._meta.app_label
diff --git a/ishtar_common/wizards.py b/ishtar_common/wizards.py
index 8308deed3..1d5e95647 100644
--- a/ishtar_common/wizards.py
+++ b/ishtar_common/wizards.py
@@ -776,6 +776,8 @@ class Wizard(IshtarWizard):
c_item = m.related.model(**other_objs[dependant_item])
setattr(obj, dependant_item, c_item)
obj.save()
+ # test framework do not reinit well this settings
+ obj._no_down_model_update = False
obj.save()
else:
adds = {}