Performance: Remove 'AllKnownLayouts' as much as possible

This commit is contained in:
Pieter Vander Vennet 2023-10-19 16:34:42 +02:00
parent 0e4cce59ea
commit 0f60977b6d
7 changed files with 27 additions and 64 deletions

View file

@ -49,14 +49,4 @@ export class AllKnownLayoutsLazy {
export class AllKnownLayouts {
public static allKnownLayouts: AllKnownLayoutsLazy = new AllKnownLayoutsLazy()
static AllPublicLayers() {
const layers = [].concat(
...this.allKnownLayouts
.values()
.filter((layout) => !layout.hideFromOverview)
.map((layout) => layout.layers)
)
return layers
}
}

View file

@ -2,7 +2,7 @@ import LayerConfig from "../Models/ThemeConfig/LayerConfig"
import { Utils } from "../Utils"
import known_layers from "../assets/generated/known_layers.json"
import { LayerConfigJson } from "../Models/ThemeConfig/Json/LayerConfigJson"
import { AllKnownLayouts } from "./AllKnownLayouts"
export class AllSharedLayers {
public static sharedLayers: Map<string, LayerConfig> = AllSharedLayers.getSharedLayers()
public static getSharedLayersConfigs(): Map<string, LayerConfigJson> {
@ -35,34 +35,4 @@ export class AllSharedLayers {
return sharedLayers
}
public static AllPublicLayers(options?: {
includeInlineLayers: true | boolean
}): LayerConfig[] {
const allLayers: LayerConfig[] = []
const seendIds = new Set<string>()
AllSharedLayers.sharedLayers.forEach((layer, key) => {
seendIds.add(key)
allLayers.push(layer)
})
if (options?.includeInlineLayers ?? true) {
const publicLayouts = Array.from(AllKnownLayouts.allKnownLayouts.values()).filter(
(l) => !l.hideFromOverview
)
for (const layout of publicLayouts) {
if (layout.hideFromOverview) {
continue
}
for (const layer of layout.layers) {
if (seendIds.has(layer.id)) {
continue
}
seendIds.add(layer.id)
allLayers.push(layer)
}
}
}
return allLayers
}
}

View file

@ -3,9 +3,6 @@ import { QueryParameters } from "./Web/QueryParameters"
import { AllKnownLayouts } from "../Customizations/AllKnownLayouts"
import { FixedUiElement } from "../UI/Base/FixedUiElement"
import { Utils } from "../Utils"
import Combine from "../UI/Base/Combine"
import { SubtleButton } from "../UI/Base/SubtleButton"
import BaseUIElement from "../UI/BaseUIElement"
import { UIEventSource } from "./UIEventSource"
import { LocalStorageSource } from "./Web/LocalStorageSource"
import LZString from "lz-string"
@ -16,7 +13,6 @@ import { PrepareTheme } from "../Models/ThemeConfig/Conversion/PrepareTheme"
import licenses from "../assets/generated/license_info.json"
import TagRenderingConfig from "../Models/ThemeConfig/TagRenderingConfig"
import { FixImages } from "../Models/ThemeConfig/Conversion/FixImages"
import Svg from "../Svg"
import questions from "../assets/generated/layers/questions.json"
import {
DoesImageExist,

View file

@ -43,7 +43,7 @@ export class ChangesetHandler {
this.userDetails = osmConnection.userDetails
this.backend = osmConnection._oauth_config.url
if (dryRun) {
if (dryRun.data) {
console.log("DRYRUN ENABLED")
}
}

View file

@ -161,6 +161,7 @@ export class OsmConnection {
this.userDetails.ping()
console.log("Logged out")
this.loadingStatus.setData("not-attempted")
this.preferencesHandler.preferences.setData(undefined)
}
/**

View file

@ -1,7 +1,6 @@
import jsPDF, { Matrix } from "jspdf"
import { Translation, TypedTranslation } from "../UI/i18n/Translation"
import { PngMapCreator } from "./pngMapCreator"
import { AllKnownLayouts } from "../Customizations/AllKnownLayouts"
import "../../public/assets/fonts/Ubuntu-M-normal.js"
import "../../public/assets/fonts/Ubuntu-L-normal.js"
import "../../public/assets/fonts/UbuntuMono-B-bold.js"
@ -874,7 +873,7 @@ class SvgToPdfPage {
width,
height,
}).CreatePng(this.options.freeComponentId, this._state)
} else {
}/* else {
const match = spec.match(/\$map\(([^)]*)\)$/)
if (match === null) {
throw "Invalid mapspec:" + spec
@ -974,7 +973,7 @@ class SvgToPdfPage {
throw "PngCreator did not output anything..."
}
}
//*/
svgImage.setAttribute("xlink:href", await SvgToPdfPage.blobToBase64(png))
smallestRect.parentElement.insertBefore(svgImage, smallestRect)
await this.prepareElement(svgImage, [], false)
@ -1052,11 +1051,6 @@ export class SvgToPdf {
constructor(title: string, pages: string[], options: SvgToPdfOptions) {
this._title = title
options.textSubstitutions = options.textSubstitutions ?? {}
options.textSubstitutions["mapCount"] =
"" +
Array.from(AllKnownLayouts.allKnownLayouts.values()).filter(
(th) => !th.hideFromOverview
).length
const state = new UIEventSource<string>("Initializing...")
this.status = state

File diff suppressed because one or more lines are too long