skip the selection-edge query where nothing reads it
The temporal timeline summarises every snapshot in a series. Each summary now also counts how many features the selection edge cuts, but a timeline point renders values only, so that was one database round trip per snapshot for a disclosure nobody sees. Make it opt-out and have the timeline opt out. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -171,11 +171,15 @@ class TemporalAnalysisService:
|
|||||||
|
|
||||||
summaries: dict[UUID, dict[str, Any]] = {}
|
summaries: dict[UUID, dict[str, Any]] = {}
|
||||||
|
|
||||||
def summarize(dataset: Dataset) -> dict[str, Any]:
|
def summarize(dataset: Dataset, *, disclose_selection_edge: bool = True) -> dict[str, Any]:
|
||||||
cached = summaries.get(dataset.id)
|
cached = summaries.get(dataset.id)
|
||||||
if cached is not None:
|
if cached is not None:
|
||||||
return cached
|
return cached
|
||||||
kwargs: dict[str, Any] = {"dataset": dataset, "bbox": bbox}
|
kwargs: dict[str, Any] = {
|
||||||
|
"dataset": dataset,
|
||||||
|
"bbox": bbox,
|
||||||
|
"disclose_selection_edge": disclose_selection_edge,
|
||||||
|
}
|
||||||
if selection_area is not None:
|
if selection_area is not None:
|
||||||
dataset_is_preclipped = is_preclipped_to_selection_area(dataset)
|
dataset_is_preclipped = is_preclipped_to_selection_area(dataset)
|
||||||
kwargs["selection_geometry"] = None if dataset_is_preclipped else selection_geometry
|
kwargs["selection_geometry"] = None if dataset_is_preclipped else selection_geometry
|
||||||
@@ -234,7 +238,9 @@ class TemporalAnalysisService:
|
|||||||
project_id=project_id,
|
project_id=project_id,
|
||||||
series_key=earlier.temporal_series_key,
|
series_key=earlier.temporal_series_key,
|
||||||
fallback_datasets=[earlier, later],
|
fallback_datasets=[earlier, later],
|
||||||
summarize=summarize,
|
# A timeline point shows values only, so the per-snapshot
|
||||||
|
# selection-edge query would be a round trip nobody reads.
|
||||||
|
summarize=lambda dataset: summarize(dataset, disclose_selection_edge=False),
|
||||||
)
|
)
|
||||||
|
|
||||||
return TemporalComparisonResponse(
|
return TemporalComparisonResponse(
|
||||||
|
|||||||
@@ -811,6 +811,7 @@ class VectorFeatureService:
|
|||||||
selection_geometry: Any | None = None,
|
selection_geometry: Any | None = None,
|
||||||
full_dataset_area: bool = False,
|
full_dataset_area: bool = False,
|
||||||
preclipped_partition_filter: tuple[str, str] | None = None,
|
preclipped_partition_filter: tuple[str, str] | None = None,
|
||||||
|
disclose_selection_edge: bool = True,
|
||||||
) -> dict[str, Any]:
|
) -> dict[str, Any]:
|
||||||
normalized_bbox = VectorFeatureService._normalize_selection_bbox(bbox)
|
normalized_bbox = VectorFeatureService._normalize_selection_bbox(bbox)
|
||||||
selection_shape = selection_geometry
|
selection_shape = selection_geometry
|
||||||
@@ -842,7 +843,7 @@ class VectorFeatureService:
|
|||||||
# How many of the counted features the selection edge cuts. Skipped for
|
# How many of the counted features the selection edge cuts. Skipped for
|
||||||
# a pre-clipped whole-area selection, which has no edge to cut against.
|
# a pre-clipped whole-area selection, which has no edge to cut against.
|
||||||
fully_covered_feature_count: int | None = None
|
fully_covered_feature_count: int | None = None
|
||||||
if not full_dataset_area and feature_count:
|
if disclose_selection_edge and not full_dataset_area and feature_count:
|
||||||
try:
|
try:
|
||||||
fully_covered_feature_count = int(
|
fully_covered_feature_count = int(
|
||||||
db.query(func.count(VectorFeature.id))
|
db.query(func.count(VectorFeature.id))
|
||||||
|
|||||||
@@ -320,7 +320,7 @@ def test_temporal_compare_returns_delta_and_canonical_change_payload(monkeypatch
|
|||||||
def get_dataset(_db, _project_id, dataset_id, _label):
|
def get_dataset(_db, _project_id, dataset_id, _label):
|
||||||
return earlier if dataset_id == earlier.id else later
|
return earlier if dataset_id == earlier.id else later
|
||||||
|
|
||||||
def summarize(_db, *, dataset, bbox): # noqa: ARG001
|
def summarize(_db, *, dataset, bbox, disclose_selection_edge=True): # noqa: ARG001
|
||||||
value = 100.0 if dataset.id == earlier.id else 115.0
|
value = 100.0 if dataset.id == earlier.id else 115.0
|
||||||
return {
|
return {
|
||||||
"metric_label": "Inwoners",
|
"metric_label": "Inwoners",
|
||||||
@@ -386,7 +386,7 @@ def test_temporal_comparison_clips_cross_boundary_bbox_to_selected_area(monkeypa
|
|||||||
staticmethod(lambda _db, _project_id, requested_area_id: area if requested_area_id == area_id else None),
|
staticmethod(lambda _db, _project_id, requested_area_id: area if requested_area_id == area_id else None),
|
||||||
)
|
)
|
||||||
|
|
||||||
def summarize(_db, *, dataset, bbox, selection_geometry, full_dataset_area): # noqa: ARG001
|
def summarize(_db, *, dataset, bbox, selection_geometry, full_dataset_area, disclose_selection_edge=True): # noqa: ARG001
|
||||||
captured_geometries.append(selection_geometry)
|
captured_geometries.append(selection_geometry)
|
||||||
return {
|
return {
|
||||||
"metric_label": "Oppervlakte",
|
"metric_label": "Oppervlakte",
|
||||||
|
|||||||
Reference in New Issue
Block a user