From f39d99b2fd12f99f5c37e27ea22d04bc95905c36 Mon Sep 17 00:00:00 2001 From: mpeltriaux Date: Sat, 26 Oct 2024 10:17:09 +0200 Subject: [PATCH 1/2] # Parcel recalculation optimization * enhances workflow for parcel recalculation --- konova/management/commands/recalculate_parcels.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/konova/management/commands/recalculate_parcels.py b/konova/management/commands/recalculate_parcels.py index e69cab8d..da3c3269 100644 --- a/konova/management/commands/recalculate_parcels.py +++ b/konova/management/commands/recalculate_parcels.py @@ -34,7 +34,9 @@ class Command(BaseKonovaCommand): def recalculate_parcels(self, options: dict): force_all = options.get("force_all", False) - geometry_objects = Geometry.objects.all() + geometry_objects = Geometry.objects.all().exclude( + geom=None + ) if not force_all: # Fetch all intersections @@ -46,16 +48,17 @@ class Command(BaseKonovaCommand): "geometry__id", flat=True ) - # Filter those geometries out (they have intersections and do not need to be processed) - geometry_objects = geometry_objects.exclude( + intersected_geom_objs = Geometry.objects.filter( id__in=geom_with_intersection_ids ) + # Filter those geometries out (they have intersections and do not need to be processed) + geometry_objects = geometry_objects.difference(intersected_geom_objs) self._write_warning("=== Update parcels and districts ===") # Order geometries by size to process smaller once at first - geometries = geometry_objects.exclude( - geom=None - ).annotate(area=Area("geom")).order_by( + geometries = geometry_objects.annotate( + area=Area("geom") + ).order_by( 'area' ) self._write_warning(f"Process parcels for {geometries.count()} geometry entries now ...") -- 2.45.2 From eb528de48b54f3e50dde1e159a8e2efa1a28a497 Mon Sep 17 00:00:00 2001 From: mpeltriaux Date: Sat, 26 Oct 2024 10:24:10 +0200 Subject: [PATCH 2/2] # Drop atomic transaction * drops atomic transaction processing on Parcel.make_unique --- konova/models/parcel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/konova/models/parcel.py b/konova/models/parcel.py index 7fafba52..371d2d14 100644 --- a/konova/models/parcel.py +++ b/konova/models/parcel.py @@ -159,7 +159,6 @@ class Parcel(UuidModel): return f"{self.parcel_group} | {self.flr} | {self.flrstck_zhlr} | {self.flrstck_nnr}" @classmethod - @transaction.atomic def make_unique(cls, **kwargs): """ Checks for duplicates of a Parcel, choose a (now) unique one, repairs relations for ParcelIntersection and removes duplicates. @@ -188,6 +187,7 @@ class Parcel(UuidModel): intersection_objs = ParcelIntersection.objects.filter( parcel__in=parcel_objs ) + # Change each intersection, so they point on the 'true one' parcel from now on for intersection in intersection_objs: intersection.parcel = unique_parcel -- 2.45.2