performance: Make _referencing_ways actually lazy

This commit is contained in:
Pieter Vander Vennet 2023-03-21 20:59:31 +01:00
parent 3eee9bd9f8
commit b99588b4ba
2 changed files with 71 additions and 32 deletions

View file

@ -80,20 +80,25 @@ export class ReferencingWaysMetaTagger extends SimpleMetaTagger {
if (!id.startsWith("node/")) {
return false
}
console.trace("Downloading referencing ways for", feature.properties.id)
OsmObject.DownloadReferencingWays(id).then((referencingWays) => {
const currentTagsSource = state.allElements?.getEventSourceById(id) ?? []
const wayIds = referencingWays.map((w) => "way/" + w.id)
wayIds.sort()
const wayIdsStr = wayIds.join(";")
if (
wayIdsStr !== "" &&
currentTagsSource.data["_referencing_ways"] !== wayIdsStr
) {
currentTagsSource.data["_referencing_ways"] = wayIdsStr
currentTagsSource.ping()
const currentTagsSource = state.allElements?.getEventSourceById(id)
if (currentTagsSource === undefined) {
return
}
Utils.AddLazyPropertyAsync(
currentTagsSource.data,
"_referencing_ways",
async () => {
const referencingWays = await OsmObject.DownloadReferencingWays(id)
const wayIds = referencingWays.map((w) => "way/" + w.id)
wayIds.sort()
const wayIdsStr = wayIds.join(";")
if (wayIdsStr !== "" && currentTagsSource.data[""] !== wayIdsStr) {
currentTagsSource.data["_referencing_ways"] = wayIdsStr
currentTagsSource.ping()
}
}
})
)
return true
}
@ -282,16 +287,9 @@ export default class SimpleMetaTaggers {
},
})
Object.defineProperty(feature.properties, "_surface:ha", {
enumerable: false,
configurable: true,
get: () => {
const sqMeters = GeoOperations.surfaceAreaInSqMeters(feature)
const sqMetersHa = "" + Math.floor(sqMeters / 1000) / 10
delete feature.properties["_surface:ha"]
feature.properties["_surface:ha"] = sqMetersHa
return sqMetersHa
},
Utils.AddLazyProperty(feature.properties, "_surface:ha", () => {
const sqMeters = GeoOperations.surfaceAreaInSqMeters(feature)
return "" + Math.floor(sqMeters / 1000) / 10
})
return true
@ -443,8 +441,6 @@ export default class SimpleMetaTaggers {
}
},
})
const tagsSource = state.allElements.getEventSourceById(feature.properties.id)
}
)
private static directionSimplified = new SimpleMetaTagger(