From 46a2a4ff465594dd1185b75c7fe1e67d96307f5e Mon Sep 17 00:00:00 2001 From: mpeltriaux Date: Sat, 26 Oct 2024 10:17:09 +0200 Subject: [PATCH] # 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 ...")