forked from MapComplete/MapComplete
		
	Performance: prepare dropping the NSI-logos from the repo
This commit is contained in:
		
							parent
							
								
									164b02c8ff
								
							
						
					
					
						commit
						555075edfe
					
				
					 3 changed files with 17 additions and 26 deletions
				
			
		| 
						 | 
					@ -9,19 +9,8 @@ import { And } from "../src/Logic/Tags/And"
 | 
				
			||||||
import Script from "./Script"
 | 
					import Script from "./Script"
 | 
				
			||||||
import NameSuggestionIndex from "../src/Logic/Web/NameSuggestionIndex"
 | 
					import NameSuggestionIndex from "../src/Logic/Web/NameSuggestionIndex"
 | 
				
			||||||
import TagInfo from "../src/Logic/Web/TagInfo"
 | 
					import TagInfo from "../src/Logic/Web/TagInfo"
 | 
				
			||||||
 | 
					import { TagsFilter } from "../src/Logic/Tags/TagsFilter"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Utilities {
 | 
					 | 
				
			||||||
    static mapValues<X extends string | number, T, TOut>(
 | 
					 | 
				
			||||||
        record: Record<X, T>,
 | 
					 | 
				
			||||||
        f: (t: T) => TOut
 | 
					 | 
				
			||||||
    ): Record<X, TOut> {
 | 
					 | 
				
			||||||
        const newR = <Record<X, TOut>>{}
 | 
					 | 
				
			||||||
        for (const x in record) {
 | 
					 | 
				
			||||||
            newR[x] = f(record[x])
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return newR
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
class GenerateStats extends Script {
 | 
					class GenerateStats extends Script {
 | 
				
			||||||
    async createOptimizationFile(includeTags = true) {
 | 
					    async createOptimizationFile(includeTags = true) {
 | 
				
			||||||
| 
						 | 
					@ -38,7 +27,7 @@ class GenerateStats extends Script {
 | 
				
			||||||
                continue
 | 
					                continue
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            const sourcesList = [TagUtils.Tag(layer.source["osmTags"])]
 | 
					            const sourcesList: TagsFilter[] = [TagUtils.Tag(layer.source["osmTags"])]
 | 
				
			||||||
            if (layer?.title) {
 | 
					            if (layer?.title) {
 | 
				
			||||||
                sourcesList.push(...new TagRenderingConfig(layer.title).usedTags())
 | 
					                sourcesList.push(...new TagRenderingConfig(layer.title).usedTags())
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
| 
						 | 
					@ -120,7 +109,7 @@ class GenerateStats extends Script {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const allBrands = Object.keys(data)
 | 
					        const allBrands = Object.keys(data)
 | 
				
			||||||
        allBrands.sort()
 | 
					        allBrands.sort()
 | 
				
			||||||
        for (const country of allCountries) {
 | 
					        for (const country of Array.from(allCountries)) {
 | 
				
			||||||
            const summary = <Record<string, number>>{}
 | 
					            const summary = <Record<string, number>>{}
 | 
				
			||||||
            for (const brand of allBrands) {
 | 
					            for (const brand of allBrands) {
 | 
				
			||||||
                const count = data[brand][country]
 | 
					                const count = data[brand][country]
 | 
				
			||||||
| 
						 | 
					@ -150,7 +139,7 @@ class GenerateStats extends Script {
 | 
				
			||||||
                path
 | 
					                path
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        const nsi = await NameSuggestionIndex.getNsiIndex()
 | 
					        const nsi = await NameSuggestionIndex.getNsiIndex("./assets/data/nsi/")
 | 
				
			||||||
        const allBrandNames: string[] = Utils.Dedup(
 | 
					        const allBrandNames: string[] = Utils.Dedup(
 | 
				
			||||||
            nsi.allPossible(<any>type).map((item) => item.tags[type])
 | 
					            nsi.allPossible(<any>type).map((item) => item.tags[type])
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -42,7 +42,7 @@ class NsiLogos extends Script {
 | 
				
			||||||
        let path = basePath + nsiItem.id
 | 
					        let path = basePath + nsiItem.id
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const logos = nsiWD["wikidata"][nsiItem?.tags?.[type + ":wikidata"]]?.logos
 | 
					        const logos = nsiWD["wikidata"][nsiItem?.tags?.[type + ":wikidata"]]?.logos
 | 
				
			||||||
        const nsi = await NameSuggestionIndex.getNsiIndex()
 | 
					        const nsi = await NameSuggestionIndex.getNsiIndex("./assets/data/nsi/")
 | 
				
			||||||
        if (nsi.isSvg(nsiItem, type)) {
 | 
					        if (nsi.isSvg(nsiItem, type)) {
 | 
				
			||||||
            path = path + ".svg"
 | 
					            path = path + ".svg"
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					@ -104,7 +104,7 @@ class NsiLogos extends Script {
 | 
				
			||||||
     * @param type
 | 
					     * @param type
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    async downloadFor(type: string): Promise<{ downloadCount: number; errored: number }> {
 | 
					    async downloadFor(type: string): Promise<{ downloadCount: number; errored: number }> {
 | 
				
			||||||
        const nsi = await NameSuggestionIndex.getNsiIndex()
 | 
					        const nsi = await NameSuggestionIndex.getNsiIndex("./assets/data/nsi/")
 | 
				
			||||||
        const items = nsi.allPossible(type)
 | 
					        const items = nsi.allPossible(type)
 | 
				
			||||||
        const basePath = "./public/assets/data/nsi/logos/"
 | 
					        const basePath = "./public/assets/data/nsi/logos/"
 | 
				
			||||||
        let downloadCount = 0
 | 
					        let downloadCount = 0
 | 
				
			||||||
| 
						 | 
					@ -158,7 +158,7 @@ class NsiLogos extends Script {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private async generateRendering(type: string) {
 | 
					    private async generateRendering(type: string) {
 | 
				
			||||||
        const nsi = await NameSuggestionIndex.getNsiIndex()
 | 
					        const nsi = await NameSuggestionIndex.getNsiIndex("./assets/data/nsi/")
 | 
				
			||||||
        const items = nsi.allPossible(type)
 | 
					        const items = nsi.allPossible(type)
 | 
				
			||||||
        const filterOptions: FilterConfigOptionJson[] = items.map((item) => {
 | 
					        const filterOptions: FilterConfigOptionJson[] = items.map((item) => {
 | 
				
			||||||
            return {
 | 
					            return {
 | 
				
			||||||
| 
						 | 
					@ -278,7 +278,7 @@ class NsiLogos extends Script {
 | 
				
			||||||
     * @private
 | 
					     * @private
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    private static async prune() {
 | 
					    private static async prune() {
 | 
				
			||||||
        const nsi = await NameSuggestionIndex.getNsiIndex()
 | 
					        const nsi = await NameSuggestionIndex.getNsiIndex("./assets/data/nsi/")
 | 
				
			||||||
        const types = nsi.supportedTypes()
 | 
					        const types = nsi.supportedTypes()
 | 
				
			||||||
        const ids = new Set<string>()
 | 
					        const ids = new Set<string>()
 | 
				
			||||||
        for (const t of types) {
 | 
					        for (const t of types) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -262,14 +262,15 @@ export class NameSuggestionIndexLight {
 | 
				
			||||||
        if (NameSuggestionIndexLight.initedLight) {
 | 
					        if (NameSuggestionIndexLight.initedLight) {
 | 
				
			||||||
            return NameSuggestionIndexLight.initedLight
 | 
					            return NameSuggestionIndexLight.initedLight
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        const endpoint = Constants.nsiLogosEndpoint ?? "./assets/data/nsi/"
 | 
				
			||||||
        const [nsi, features] = await Promise.all(
 | 
					        const [nsi, features] = await Promise.all(
 | 
				
			||||||
            [
 | 
					            [
 | 
				
			||||||
                "./assets/data/nsi/nsi.min.json",
 | 
					                endpoint + "nsi.min.json",
 | 
				
			||||||
                "./assets/data/nsi/featureCollection.min.json"
 | 
					                endpoint + "featureCollection.min.json"
 | 
				
			||||||
            ].map((url) => Utils.downloadJsonCached(url, 1000 * 60 * 60 * 24 * 30))
 | 
					            ].map((url) => Utils.downloadJsonCached(url, 1000 * 60 * 60 * 24 * 30))
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        return new NameSuggestionIndexLight(
 | 
					        return new NameSuggestionIndexLight(
 | 
				
			||||||
            Constants.nsiLogosEndpoint,
 | 
					            endpoint,
 | 
				
			||||||
            <any>nsi,
 | 
					            <any>nsi,
 | 
				
			||||||
            <any>features
 | 
					            <any>features
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
| 
						 | 
					@ -310,15 +311,16 @@ export default class NameSuggestionIndex extends NameSuggestionIndexLight {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static async getNsiIndex(): Promise<NameSuggestionIndex> {
 | 
					    public static async getNsiIndex(endPoint ?: string): Promise<NameSuggestionIndex> {
 | 
				
			||||||
        if (NameSuggestionIndex.inited) {
 | 
					        if (NameSuggestionIndex.inited) {
 | 
				
			||||||
            return NameSuggestionIndex.inited
 | 
					            return NameSuggestionIndex.inited
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        endPoint ??= Constants.nsiLogosEndpoint ?? "./assets/data/nsi/"
 | 
				
			||||||
        const [nsi, nsiWd, features] = await Promise.all(
 | 
					        const [nsi, nsiWd, features] = await Promise.all(
 | 
				
			||||||
            [
 | 
					            [
 | 
				
			||||||
                "./assets/data/nsi/nsi.min.json",
 | 
					                endPoint + "nsi.min.json",
 | 
				
			||||||
                "./assets/data/nsi/wikidata.min.json",
 | 
					                endPoint + "wikidata.min.json",
 | 
				
			||||||
                "./assets/data/nsi/featureCollection.min.json"
 | 
					                endPoint + "featureCollection.min.json"
 | 
				
			||||||
            ].map((url) => Utils.downloadJsonCached(url, 1000 * 60 * 60 * 24 * 30))
 | 
					            ].map((url) => Utils.downloadJsonCached(url, 1000 * 60 * 60 * 24 * 30))
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        return new NameSuggestionIndex(
 | 
					        return new NameSuggestionIndex(
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue