From 3cc7d05e03809616823cdf4f0143ae230e195638 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Mon, 3 Feb 2025 02:32:06 +0100 Subject: [PATCH] Fix: don't save big objects to the cache, see #1919 --- .../Actors/SaveFeatureSourceToLocalStorage.ts | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/Logic/FeatureSource/Actors/SaveFeatureSourceToLocalStorage.ts b/src/Logic/FeatureSource/Actors/SaveFeatureSourceToLocalStorage.ts index 59cf8b51b..502d27407 100644 --- a/src/Logic/FeatureSource/Actors/SaveFeatureSourceToLocalStorage.ts +++ b/src/Logic/FeatureSource/Actors/SaveFeatureSourceToLocalStorage.ts @@ -13,6 +13,7 @@ class SingleTileSaver { private readonly _registeredIds = new Set() private readonly _featureProperties: FeaturePropertiesStore private readonly _isDirty = new UIEventSource(false) + constructor( storage: UIEventSource & { flush: () => void }, featureProperties: FeaturePropertiesStore @@ -62,6 +63,7 @@ class SingleTileSaver { export default class SaveFeatureSourceToLocalStorage { public readonly storage: TileLocalStorage private readonly zoomlevel: number + constructor( backend: string, layername: string, @@ -75,8 +77,25 @@ export default class SaveFeatureSourceToLocalStorage { this.storage = storage const singleTileSavers: Map = new Map() features.features.addCallbackAndRunD((features) => { + if (features.some(f => { + let totalPoints = 0 + if (f.geometry.type === "MultiPolygon") { + totalPoints = f.geometry.coordinates.map(rings => rings.map(ring => ring.length).reduce((a, b) => a + b)).reduce((a, b) => a + b) + } else if (f.geometry.type === "Polygon" || f.geometry.type === "MultiLineString") { + totalPoints = f.geometry.coordinates.map(ring => ring.length).reduce((a, b) => a + b) + } else if (f.geometry.type === "LineString") { + totalPoints = f.geometry.coordinates.length + } + if (totalPoints > 1000) { + console.warn(`Not caching tiles, detected a big object (${totalPoints} points for ${f.properties.id})`) + return true + } + return false + })) { + // Has big objects + return + } const sliced = GeoOperations.spreadIntoBboxes(features, zoomlevel) - sliced.forEach((features, tileIndex) => { let tileSaver = singleTileSavers.get(tileIndex) if (tileSaver === undefined) {