From 27eac8dc6cf0e96f78edfe4e09845e454fb6d510 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Thu, 21 Sep 2023 16:35:51 +0200 Subject: ⚡️ imports: prevent unecessary copy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ishtar_common/models_imports.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'ishtar_common/models_imports.py') diff --git a/ishtar_common/models_imports.py b/ishtar_common/models_imports.py index 78398ea1a..ca0a38832 100644 --- a/ishtar_common/models_imports.py +++ b/ishtar_common/models_imports.py @@ -1421,12 +1421,16 @@ class BaseImport(models.Model): self.state = state self.save() # only save if no save previously + def get_imported_images(self): + return self.imported_images + def save(self, *args, **kwargs): super().save(*args, **kwargs) if ( self.state == "AC" and not getattr(self, "_archive_pending", False) and not self.archive_file + and not getattr(self, "group", False) ): self._archive() @@ -1618,7 +1622,7 @@ class ImportGroup(BaseImport): f.path = w_filename setattr(current_import, attr, f) current_import.save() - getattr(current_import, attr).name = w_filename + getattr(current_import, attr).name = w_filename[len(settings.MEDIA_ROOT):] current_import.save() os.remove(self.archive_file.path) self.refresh_from_db() @@ -1694,12 +1698,11 @@ class ImportGroup(BaseImport): except FileNotFoundError: pass setattr(sub_import, attr, None) + sub_import.state = "AC" + sub_import.save() self.save() self._archive_pending = False - def archive(self): - super().archive() - self.imports.update(state="AC") def get_all_imported(self): imported = [] @@ -1725,10 +1728,10 @@ class ImportGroup(BaseImport): imported_images.name = self.imported_images.name.split(os.sep)[-1] for import_type_relation in self.importer_type.importer_types.all(): - import_type = import_type_relation.importer_type + importer_type = import_type_relation.importer_type imp = Import.objects.create( name=name, - importer_type=import_type, + importer_type=importer_type, group=self, ) imports.append(imp) @@ -1737,7 +1740,7 @@ class ImportGroup(BaseImport): if imported_file: imp.imported_file = imported_file modified = True - if import_type.archive_required and imported_images: + if importer_type.archive_required and imported_images: imp.imported_images = imported_images modified = True if modified: @@ -1841,6 +1844,12 @@ class Import(BaseImport): TargetKey.objects.filter(associated_import=self, is_set=False).count() ) + def get_imported_images(self): + if not self.group: + return self.imported_images + if self.importer_type.archive_required: + return self.group.imported_images + @property def errors(self): if not self.error_file: -- cgit v1.2.3