perf(jslib): add `attr` cache
ci/woodpecker/push/woodpecker Pipeline failed Details

refactor/sveltekit
Tomáš Mládek 2023-12-03 19:28:24 +01:00
parent b99f9bc15c
commit 2027b543fd
2 changed files with 21 additions and 16 deletions

View File

@ -66,26 +66,31 @@ export class UpObject {
);
}
private _attr: { [key: string]: UpEntry[] } | undefined;
public get attr() {
const result = {} as { [key: string]: UpEntry[] };
this.attributes.forEach((entry) => {
if (!result[entry.attribute]) {
result[entry.attribute] = [];
}
if (!this._attr) {
const result = {} as { [key: string]: UpEntry[] };
this.attributes.forEach((entry) => {
if (!result[entry.attribute]) {
result[entry.attribute] = [];
}
result[entry.attribute].push(entry);
});
result[entry.attribute].push(entry);
});
this.backlinks.forEach((entry) => {
const attribute = `~${entry.attribute}`;
if (!result[attribute]) {
result[attribute] = [];
}
this.backlinks.forEach((entry) => {
const attribute = `~${entry.attribute}`;
if (!result[attribute]) {
result[attribute] = [];
}
result[attribute].push(entry);
});
result[attribute].push(entry);
});
return result;
this._attr = result;
}
return this._attr;
}
public get(attr: string) {

View File

@ -1,6 +1,6 @@
{
"name": "@upnd/upend",
"version": "0.2.0",
"version": "0.2.1",
"description": "Client library to interact with the UpEnd system.",
"scripts": {
"build": "tsc --build --verbose",