diff --git a/konova/management/commands/recalculate_parcels.py b/konova/management/commands/recalculate_parcels.py index da3c3269..42165c5f 100644 --- a/konova/management/commands/recalculate_parcels.py +++ b/konova/management/commands/recalculate_parcels.py @@ -48,11 +48,14 @@ class Command(BaseKonovaCommand): "geometry__id", flat=True ) + # ... and resolve into Geometry objects again ... 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) + # ... to be able to use the way more efficient difference() function ... + geometry_objects_ids = geometry_objects.difference(intersected_geom_objs).values_list("id", flat=True) + # ... so we can resolve these into proper Geometry objects again for further annotation usage + geometry_objects = Geometry.objects.filter(id__in=geometry_objects_ids) self._write_warning("=== Update parcels and districts ===") # Order geometries by size to process smaller once at first