forked from MapComplete/MapComplete
		
	Fix performance issues
This commit is contained in:
		
							parent
							
								
									459489dedf
								
							
						
					
					
						commit
						b9cd30cb1f
					
				
					 1 changed files with 16 additions and 6 deletions
				
			
		|  | @ -5,12 +5,12 @@ import opening_hours from "opening_hours"; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class SimpleMetaTagger { | class SimpleMetaTagger { | ||||||
|     private _f: (feature: any) => void; |     private _f: (feature: any, index: number) => void; | ||||||
|     public readonly keys: string[]; |     public readonly keys: string[]; | ||||||
|     public readonly doc: string; |     public readonly doc: string; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|     constructor(keys: string[], doc: string, f: ((feature: any) => void)) { |     constructor(keys: string[], doc: string, f: ((feature: any, index: number) => void)) { | ||||||
|         this.keys = keys; |         this.keys = keys; | ||||||
|         this.doc = doc; |         this.doc = doc; | ||||||
|         this._f = f; |         this._f = f; | ||||||
|  | @ -22,8 +22,9 @@ class SimpleMetaTagger { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     addMetaTags(features: any[]) { |     addMetaTags(features: any[]) { | ||||||
|         for (const feature of features) { |         for (let i = 0; i < features.length; i++) { | ||||||
|             this._f(feature); |             let feature = features[i]; | ||||||
|  |             this._f(feature, i); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -62,7 +63,7 @@ export default class MetaTagging { | ||||||
| 
 | 
 | ||||||
|         new SimpleMetaTagger( |         new SimpleMetaTagger( | ||||||
|             ["_country"], "The country code of the point", |             ["_country"], "The country code of the point", | ||||||
|             (feature => { |             ((feature, index) => { | ||||||
|                 const centerPoint = GeoOperations.centerpoint(feature); |                 const centerPoint = GeoOperations.centerpoint(feature); | ||||||
|                 const lat = centerPoint.geometry.coordinates[1]; |                 const lat = centerPoint.geometry.coordinates[1]; | ||||||
|                 const lon = centerPoint.geometry.coordinates[0] |                 const lon = centerPoint.geometry.coordinates[0] | ||||||
|  | @ -70,7 +71,11 @@ export default class MetaTagging { | ||||||
|                 CodeGrid.getCode(lat, lon, (error, code) => { |                 CodeGrid.getCode(lat, lon, (error, code) => { | ||||||
|                     if (error === null) { |                     if (error === null) { | ||||||
|                         feature.properties["_country"] = code; |                         feature.properties["_country"] = code; | ||||||
|                         State.state.allElements.addOrGetElement(feature).ping(); | 
 | ||||||
|  |                         // There is a huge performance issue: if there are ~1000 features receiving a ping at the same time, 
 | ||||||
|  |                         // The application hangs big time
 | ||||||
|  |                         // So we disable pinging all together
 | ||||||
|  | 
 | ||||||
|                     } else { |                     } else { | ||||||
|                         console.warn("Could not determine country for", feature.properties.id, error); |                         console.warn("Could not determine country for", feature.properties.id, error); | ||||||
|                     } |                     } | ||||||
|  | @ -85,6 +90,11 @@ export default class MetaTagging { | ||||||
| 
 | 
 | ||||||
|                     if (tags["opening_hours"] !== undefined && tags["_country"] !== undefined) { |                     if (tags["opening_hours"] !== undefined && tags["_country"] !== undefined) { | ||||||
| 
 | 
 | ||||||
|  |                         if (tags._isOpen !== undefined) { | ||||||
|  |                             // Already defined
 | ||||||
|  |                             return; | ||||||
|  |                         } | ||||||
|  | 
 | ||||||
|                         const oh = new opening_hours(tags["opening_hours"], { |                         const oh = new opening_hours(tags["opening_hours"], { | ||||||
|                             lat: tags._lat, |                             lat: tags._lat, | ||||||
|                             lon: tags._lon, |                             lon: tags._lon, | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue