mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-05-31 14:50:47 +00:00
37 lines
670 B
TypeScript
37 lines
670 B
TypeScript
import * as db from '../db';
|
|
|
|
const cache: { [appId: number]: string } = {};
|
|
|
|
export async function getCommitForApp(
|
|
appId: number,
|
|
): Promise<string | undefined> {
|
|
if (isNaN(appId)) {
|
|
return;
|
|
}
|
|
|
|
if (cache[appId] != null) {
|
|
return cache[appId];
|
|
}
|
|
|
|
const commit = await db
|
|
.models('currentCommit')
|
|
.where({ appId })
|
|
.select('commit');
|
|
|
|
if (commit?.[0] != null) {
|
|
cache[appId] = commit[0].commit;
|
|
return commit[0].commit;
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
export function upsertCommitForApp(
|
|
appId: number,
|
|
commit: string,
|
|
trx?: db.Transaction,
|
|
): Promise<void> {
|
|
cache[appId] = commit;
|
|
return db.upsertModel('currentCommit', { commit, appId }, { appId }, trx);
|
|
}
|