forked from MapComplete/MapComplete
		
	Add feature switch to disable the cache, partial fix to make GRB theme workable again
This commit is contained in:
		
							parent
							
								
									0a7d48de5b
								
							
						
					
					
						commit
						fda88fcccf
					
				
					 8 changed files with 47 additions and 31 deletions
				
			
		| 
						 | 
				
			
			@ -112,7 +112,7 @@ export default class SelectedElementTagsUpdater {
 | 
			
		|||
    private invalidateCache(s: Feature) {
 | 
			
		||||
        const state = this.state
 | 
			
		||||
        const wasPartOfLayer = state.layout.getMatchingLayer(s.properties)
 | 
			
		||||
        state.toCacheSavers.get(wasPartOfLayer.id).invalidateCacheAround(BBox.get(s))
 | 
			
		||||
        state.toCacheSavers?.get(wasPartOfLayer.id)?.invalidateCacheAround(BBox.get(s))
 | 
			
		||||
    }
 | 
			
		||||
    private installCallback() {
 | 
			
		||||
        const state = this.state
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -75,14 +75,7 @@ export default class ChangeGeometryApplicator implements FeatureSource {
 | 
			
		|||
                newFeatures.push(feature)
 | 
			
		||||
                continue
 | 
			
		||||
            }
 | 
			
		||||
            console.log(
 | 
			
		||||
                "Applying a geometry change onto:",
 | 
			
		||||
                feature,
 | 
			
		||||
                "The change is:",
 | 
			
		||||
                change,
 | 
			
		||||
                "which becomes:",
 | 
			
		||||
                copy
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
            newFeatures.push(copy)
 | 
			
		||||
        }
 | 
			
		||||
        this.features.setData(newFeatures)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -27,6 +27,7 @@ export default class LayoutSource extends FeatureSourceMerger {
 | 
			
		|||
    private readonly supportsForceDownload: UpdatableFeatureSource[]
 | 
			
		||||
 | 
			
		||||
    public static readonly fromCacheZoomLevel = 15
 | 
			
		||||
 | 
			
		||||
    constructor(
 | 
			
		||||
        layers: LayerConfig[],
 | 
			
		||||
        featureSwitches: FeatureSwitchState,
 | 
			
		||||
| 
						 | 
				
			
			@ -45,20 +46,22 @@ export default class LayoutSource extends FeatureSourceMerger {
 | 
			
		|||
        const geojsonlayers = layers.filter((layer) => layer.source.geojsonSource !== undefined)
 | 
			
		||||
        const osmLayers = layers.filter((layer) => layer.source.geojsonSource === undefined)
 | 
			
		||||
        const fromCache = new Map<string, LocalStorageFeatureSource>()
 | 
			
		||||
        for (const layer of osmLayers) {
 | 
			
		||||
            const src = new LocalStorageFeatureSource(
 | 
			
		||||
                backend,
 | 
			
		||||
                layer,
 | 
			
		||||
                LayoutSource.fromCacheZoomLevel,
 | 
			
		||||
                mapProperties,
 | 
			
		||||
                {
 | 
			
		||||
                    isActive: isDisplayed(layer.id),
 | 
			
		||||
                    maxAge: layer.maxAgeOfCache,
 | 
			
		||||
                }
 | 
			
		||||
            )
 | 
			
		||||
            fromCache.set(layer.id, src)
 | 
			
		||||
        }
 | 
			
		||||
        if (featureSwitches.featureSwitchCache.data) {
 | 
			
		||||
            for (const layer of osmLayers) {
 | 
			
		||||
                const src = new LocalStorageFeatureSource(
 | 
			
		||||
                    backend,
 | 
			
		||||
                    layer,
 | 
			
		||||
                    LayoutSource.fromCacheZoomLevel,
 | 
			
		||||
                    mapProperties,
 | 
			
		||||
                    {
 | 
			
		||||
                        isActive: isDisplayed(layer.id),
 | 
			
		||||
                        maxAge: layer.maxAgeOfCache
 | 
			
		||||
                    }
 | 
			
		||||
                )
 | 
			
		||||
                fromCache.set(layer.id, src)
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
        const mvtSources: UpdatableFeatureSource[] = osmLayers
 | 
			
		||||
            .filter((f) => mvtAvailableLayers.has(f.id))
 | 
			
		||||
            .map((l) => LayoutSource.setupMvtSource(l, mapProperties, isDisplayed(l.id)))
 | 
			
		||||
| 
						 | 
				
			
			@ -104,7 +107,6 @@ export default class LayoutSource extends FeatureSourceMerger {
 | 
			
		|||
        super(...geojsonSources, ...Array.from(fromCache.values()), ...mvtSources, ...nonMvtSources)
 | 
			
		||||
 | 
			
		||||
        this.isLoading = isLoading
 | 
			
		||||
        this.fromCache = fromCache
 | 
			
		||||
        supportsForceDownload.push(...geojsonSources)
 | 
			
		||||
        supportsForceDownload.push(...mvtSources) // Non-mvt sources are handled by overpass
 | 
			
		||||
        this.supportsForceDownload = supportsForceDownload
 | 
			
		||||
| 
						 | 
				
			
			@ -168,7 +170,7 @@ export default class LayoutSource extends FeatureSourceMerger {
 | 
			
		|||
            backend,
 | 
			
		||||
            isActive,
 | 
			
		||||
            patchRelations: true,
 | 
			
		||||
            fullNodeDatabase,
 | 
			
		||||
            fullNodeDatabase
 | 
			
		||||
        })
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -200,11 +202,11 @@ export default class LayoutSource extends FeatureSourceMerger {
 | 
			
		|||
                widenFactor: featureSwitches.layoutToUse.widenFactor,
 | 
			
		||||
                overpassUrl: featureSwitches.overpassUrl,
 | 
			
		||||
                overpassTimeout: featureSwitches.overpassTimeout,
 | 
			
		||||
                overpassMaxZoom: featureSwitches.overpassMaxZoom,
 | 
			
		||||
                overpassMaxZoom: featureSwitches.overpassMaxZoom
 | 
			
		||||
            },
 | 
			
		||||
            {
 | 
			
		||||
                padToTiles: zoom.map((zoom) => Math.min(15, zoom + 1)),
 | 
			
		||||
                isActive,
 | 
			
		||||
                isActive
 | 
			
		||||
            }
 | 
			
		||||
        )
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -57,6 +57,8 @@ export default class FeatureSwitchState extends OsmConnectionFeatureSwitches {
 | 
			
		|||
    public readonly featureSwitchBackToThemeOverview: UIEventSource<boolean>
 | 
			
		||||
    public readonly featureSwitchShareScreen: UIEventSource<boolean>
 | 
			
		||||
    public readonly featureSwitchGeolocation: UIEventSource<boolean>
 | 
			
		||||
    public readonly featureSwitchCache: UIEventSource<boolean>
 | 
			
		||||
 | 
			
		||||
    public readonly featureSwitchIsTesting: UIEventSource<boolean>
 | 
			
		||||
    public readonly featureSwitchIsDebugging: UIEventSource<boolean>
 | 
			
		||||
    public readonly featureSwitchShowAllQuestions: UIEventSource<boolean>
 | 
			
		||||
| 
						 | 
				
			
			@ -176,6 +178,13 @@ export default class FeatureSwitchState extends OsmConnectionFeatureSwitches {
 | 
			
		|||
            "Enable the export as GeoJSON and CSV button"
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        this.featureSwitchCache = FeatureSwitchUtils.initSwitch(
 | 
			
		||||
            "fs-cache",
 | 
			
		||||
            layoutToUse?.enableCache ?? true,
 | 
			
		||||
            "Enable/disable caching from localStorage"
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        let testingDefaultValue = false
 | 
			
		||||
        if (
 | 
			
		||||
            !Utils.runningFromConsole &&
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue