Performance: specify separate editor layer index

This commit is contained in:
Pieter Vander Vennet 2025-04-26 22:39:05 +02:00
parent 77af14e9c6
commit 8444cb86bc
7 changed files with 47 additions and 20 deletions

View file

@ -8,6 +8,7 @@ import { TypedTranslation } from "../../UI/i18n/Translation"
import { RegexTag } from "../Tags/RegexTag"
import { TagConfigJson } from "../../Models/ThemeConfig/Json/TagConfigJson"
import { TagUtils } from "../Tags/TagUtils"
import Constants from "../../Models/Constants"
/**
* Main name suggestion index file
@ -69,8 +70,10 @@ export default class NameSuggestionIndex {
private loco: LocationConflation // Some additional boundaries
private _supportedTypes: string[]
private _serverLocation: string
constructor(
private constructor(
serverLocation: string,
nsiFile: Readonly<NSIFile>,
nsiWdFile: Readonly<
Record<
@ -82,6 +85,7 @@ export default class NameSuggestionIndex {
>,
features: Readonly<FeatureCollection>
) {
this._serverLocation = serverLocation
this.nsiFile = nsiFile
this.nsiWdFile = nsiWdFile
this.loco = new LocationConflation(features)
@ -101,6 +105,7 @@ export default class NameSuggestionIndex {
].map((url) => Utils.downloadJsonCached(url, 1000 * 60 * 60 * 24 * 30))
)
NameSuggestionIndex.inited = new NameSuggestionIndex(
Constants.nsiLogosEndpoint,
<any>nsi,
<any>nsiWd["wikidata"],
<any>features
@ -129,12 +134,13 @@ export default class NameSuggestionIndex {
* @param countries
* @private
*/
private static async fetchFrequenciesFor(type: string, countries: string[]) {
private async fetchFrequenciesFor(type: string, countries: string[]) {
const server = this._serverLocation
let stats = await Promise.all(
countries.map((c) => {
try {
return Utils.downloadJsonCached<Record<string, number>>(
`./assets/data/nsi/stats/${type}.${c.toUpperCase()}.json`,
`${server}/stats/${type}.${c.toUpperCase()}.json`,
24 * 60 * 60 * 1000
)
} catch (e) {
@ -194,7 +200,7 @@ export default class NameSuggestionIndex {
const mappings: (Mapping & { frequency: number })[] = []
const frequencies =
country !== undefined
? await NameSuggestionIndex.fetchFrequenciesFor(type, country)
? await this.fetchFrequenciesFor(type, country)
: {}
for (const key in tags) {
if (key.startsWith("_")) {
@ -398,11 +404,12 @@ export default class NameSuggestionIndex {
}
public getIconUrl(nsiItem: NSIItem): string | undefined {
if (!nsiItem.ext) {
const baseUrl = this._serverLocation
if (!nsiItem.ext || baseUrl === null) {
// No extension -> there is no logo
return undefined
}
return "./assets/data/nsi/logos/" + nsiItem.id + "." + nsiItem.ext
return baseUrl +"/logos/"+ nsiItem.id + "." + nsiItem.ext
}
private static readonly brandPrefix = ["name", "alt_name", "operator", "brand"] as const

View file

@ -139,6 +139,7 @@ export default class Constants {
public static osmAuthConfig: AuthConfig = Constants.config.oauth_credentials
public static nominatimEndpoint: string = Constants.config.nominatimEndpoint
public static photonEndpoint: string = Constants.config.photonEndpoint
public static nsiLogosEndpoint: string = Constants.config.nsi_logos_server ?? null
public static weblate: string = "https://translate.mapcomplete.org/"
public static linkedDataProxy: string = Constants.config["jsonld-proxy"]