fixup server: refactor meta caching
All checks were successful
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/lint-client Pipeline was successful
ci/woodpecker/push/lint-foundkey-js Pipeline was successful
ci/woodpecker/push/lint-backend Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
All checks were successful
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/lint-client Pipeline was successful
ci/woodpecker/push/lint-foundkey-js Pipeline was successful
ci/woodpecker/push/lint-backend Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
fix: setting meta does not keep cache synced. fix: handle initially empty meta table.
This commit is contained in:
parent
9f6be8d557
commit
b958be77b6
1 changed files with 15 additions and 1 deletions
|
@ -15,22 +15,36 @@ export async function setMeta(meta: Meta): Promise<void> {
|
||||||
db.manager.clear(Meta);
|
db.manager.clear(Meta);
|
||||||
db.manager.insert(Meta, meta);
|
db.manager.insert(Meta, meta);
|
||||||
|
|
||||||
|
cache = meta;
|
||||||
|
|
||||||
unlock();
|
unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs the primitive database operation to fetch server configuration.
|
* Performs the primitive database operation to fetch server configuration.
|
||||||
|
* If there is no entry yet, inserts a new one.
|
||||||
* Writes to `cache` instead of returning.
|
* Writes to `cache` instead of returning.
|
||||||
*/
|
*/
|
||||||
async function getMeta(): Promise<void> {
|
async function getMeta(): Promise<void> {
|
||||||
const unlock = await getFetchInstanceMetadataLock('localhost');
|
const unlock = await getFetchInstanceMetadataLock('localhost');
|
||||||
|
|
||||||
// new IDs are prioritised because multiple records may have been created due to past bugs
|
// new IDs are prioritised because multiple records may have been created due to past bugs
|
||||||
cache = db.manager.findOne(Meta, {
|
let metas = await db.manager.find(Meta, {
|
||||||
order: {
|
order: {
|
||||||
id: 'DESC',
|
id: 'DESC',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
if (metas.length === 0) {
|
||||||
|
db.manager.insert(Meta, {
|
||||||
|
id: 'x',
|
||||||
|
});
|
||||||
|
metas = await db.manager.find(Meta, {
|
||||||
|
order: {
|
||||||
|
id: 'DESC',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
cache = metas[0];
|
||||||
|
|
||||||
unlock();
|
unlock();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue