forked from MapComplete/MapComplete
		
	Force cache clearing when a new point is added, fix #522
This commit is contained in:
		
							parent
							
								
									936cf1bf9f
								
							
						
					
					
						commit
						d1ecaf7527
					
				
					 3 changed files with 32 additions and 7 deletions
				
			
		|  | @ -4,13 +4,14 @@ | |||
|  * Technically, more an Actor then a featuresource, but it fits more neatly this ay | ||||
|  */ | ||||
| import {FeatureSourceForLayer} from "../FeatureSource"; | ||||
| import {Tiles} from "../../../Models/TileRange"; | ||||
| 
 | ||||
| export default class SaveTileToLocalStorageActor { | ||||
|     public static readonly storageKey: string = "cached-features"; | ||||
|     public static readonly formatVersion: string = "2" | ||||
| 
 | ||||
|     constructor(source: FeatureSourceForLayer, tileIndex: number) { | ||||
|          | ||||
| 
 | ||||
|         source.features.addCallbackAndRunD(features => { | ||||
|             const key = `${SaveTileToLocalStorageActor.storageKey}-${source.layer.layerDef.id}-${tileIndex}` | ||||
|             const now = new Date() | ||||
|  | @ -28,13 +29,30 @@ export default class SaveTileToLocalStorageActor { | |||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     public static MarkVisited(layerId: string, tileId: number, freshness: Date){ | ||||
|     public static MarkVisited(layerId: string, tileId: number, freshness: Date) { | ||||
|         const key = `${SaveTileToLocalStorageActor.storageKey}-${layerId}-${tileId}` | ||||
|         try{ | ||||
|         try { | ||||
|             localStorage.setItem(key + "-time", JSON.stringify(freshness.getTime())) | ||||
|             localStorage.setItem(key + "-format", SaveTileToLocalStorageActor.formatVersion) | ||||
|         }catch(e){ | ||||
|         } catch (e) { | ||||
|             console.error("Could not mark tile ", key, "as visited") | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|    public static poison(layers: string[], lon: number, lat: number) { | ||||
|         for (let z = 0; z < 25; z++) { | ||||
| 
 | ||||
|             const {x, y} = Tiles.embedded_tile(lat, lon, z) | ||||
|             const tileId = Tiles.tile_index(z, x, y) | ||||
| 
 | ||||
|             for (const layerId of layers) { | ||||
| 
 | ||||
|                 const key = `${SaveTileToLocalStorageActor.storageKey}-${layerId}-${tileId}` | ||||
|                 localStorage.removeItem(key + "-time"); | ||||
|                 localStorage.removeItem(key + "-format") | ||||
|                 localStorage.removeItem(key) | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|     } | ||||
| } | ||||
|  | @ -91,14 +91,22 @@ export default class FeaturePipeline { | |||
| 
 | ||||
|         const self = this | ||||
|         const expiryInSeconds = Math.min(...state.layoutToUse.layers.map(l => l.maxAgeOfCache)) | ||||
|         this.oldestAllowedDate = new Date(new Date().getTime() - expiryInSeconds); | ||||
|         for (const layer of state.layoutToUse.layers) { | ||||
|             TiledFromLocalStorageSource.cleanCacheForLayer(layer) | ||||
|         } | ||||
|         this.oldestAllowedDate = new Date(new Date().getTime() - expiryInSeconds); | ||||
|         this.osmSourceZoomLevel = state.osmApiTileSize.data; | ||||
|         // milliseconds
 | ||||
|         const useOsmApi = state.locationControl.map(l => l.zoom > (state.overpassMaxZoom.data ?? 12)) | ||||
|         this.relationTracker = new RelationsTracker() | ||||
|          | ||||
|         state.changes.allChanges.addCallbackAndRun(allChanges => { | ||||
|             allChanges.filter(ch => ch.id < 0) | ||||
|                 .map(ch => ch.changes) | ||||
|                 .filter(coor => coor["lat"] !== undefined && coor["lon"] !== undefined) | ||||
|                 .forEach(coor => { | ||||
|                     SaveTileToLocalStorageActor.poison(state.layoutToUse.layers.map(l => l.id), coor["lon"], coor["lat"]) | ||||
|                 }) | ||||
|         }) | ||||
| 
 | ||||
| 
 | ||||
|         this.sufficientlyZoomed = state.locationControl.map(location => { | ||||
|  |  | |||
|  | @ -47,7 +47,6 @@ export default class TiledFromLocalStorageSource implements TileHierarchy<Featur | |||
|                 localStorage.removeItem(k) | ||||
|                 localStorage.removeItem(k+"-format") | ||||
|                 localStorage.removeItem(k+"-time") | ||||
|                 console.debug("Removed "+k+" from local storage: too old") | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue