Don't fully reload when the table data is already in store

This commit is contained in:
Melon 2023-10-31 12:17:29 +00:00
parent f9f5298a4b
commit 4993a31fe6
Signed by: melon
GPG Key ID: 6C9D970C50D26A25
2 changed files with 7 additions and 2 deletions

View File

@ -26,7 +26,7 @@
return p.endsWith(domain); return p.endsWith(domain);
} }
let promiseForTable: Promise<void> = reloadTable(); let promiseForTable: Promise<void> = Object.keys($redirectsTable).length === 0 ? reloadTable() : Promise.resolve();
function reloadTable(): Promise<void> { function reloadTable(): Promise<void> {
return new Promise<void>((res, rej) => { return new Promise<void>((res, rej) => {
@ -37,12 +37,17 @@
}) })
.then(x => { .then(x => {
let rows = x as Redirect[]; let rows = x as Redirect[];
let srcs = new Set(Object.keys($redirectsTable));
rows.forEach(x => { rows.forEach(x => {
$redirectsTable[x.src] = { $redirectsTable[x.src] = {
client: !$redirectsTable[x.src] ? JSON.parse(JSON.stringify(x)) : $redirectsTable[x.src]?.client, client: !$redirectsTable[x.src] ? JSON.parse(JSON.stringify(x)) : $redirectsTable[x.src]?.client,
server: x, server: x,
p: Promise.resolve(), p: Promise.resolve(),
}; };
srcs.delete(x.src);
});
srcs.forEach(x => {
$redirectsTable[x].server = null;
}); });
res(); res();
}) })

View File

@ -26,7 +26,7 @@
return p.endsWith(domain); return p.endsWith(domain);
} }
let promiseForTable: Promise<void> = reloadTable(); let promiseForTable: Promise<void> = Object.keys($routesTable).length === 0 ? reloadTable() : Promise.resolve();
function reloadTable(): Promise<void> { function reloadTable(): Promise<void> {
return new Promise<void>((res, rej) => { return new Promise<void>((res, rej) => {