diff --git a/src/renderer/preload/platform/Windows/winget.ts b/src/renderer/preload/platform/Windows/winget.ts index a49706c..550a56e 100644 --- a/src/renderer/preload/platform/Windows/winget.ts +++ b/src/renderer/preload/platform/Windows/winget.ts @@ -58,9 +58,10 @@ const winget: IPCWinget = { } catch (e) {} const nowTime = new Date().getTime(); + const lastFullIndexTime = cacheDB_lastFullIndexJsTimestamp("winget"); + const secondsSinceIndexBuilt = (nowTime - lastFullIndexTime) / 1000; const indexTooOld = - (nowTime - cacheDB_lastFullIndexJsTimestamp()) / 1000 > - (await getFullIndexIntervalInSeconds()); + secondsSinceIndexBuilt > (await getFullIndexIntervalInSeconds()); if ( !indexExists || @@ -82,7 +83,7 @@ const winget: IPCWinget = { (winget as any)._ingestPackageInfo(undefined, manifests); (winget as any)._postIndexing(); - cacheDB_updateLastFullIndexJsTimestamp(); + cacheDB_updateLastFullIndexJsTimestamp("winget"); }, async indexOutdated(): Promise { diff --git a/src/renderer/preload/platform/macOS/brew.ts b/src/renderer/preload/platform/macOS/brew.ts index b798801..5eef3c5 100644 --- a/src/renderer/preload/platform/macOS/brew.ts +++ b/src/renderer/preload/platform/macOS/brew.ts @@ -74,9 +74,10 @@ const brew: IPCBrew = { } catch (e) {} const nowTime = new Date().getTime(); + const lastFullIndexTime = cacheDB_lastFullIndexJsTimestamp("brew"); + const secondsSinceIndexBuilt = (nowTime - lastFullIndexTime) / 1000; const indexTooOld = - (nowTime - cacheDB_lastFullIndexJsTimestamp()) / 1000 > - (await getFullIndexIntervalInSeconds()); + secondsSinceIndexBuilt > (await getFullIndexIntervalInSeconds()); if ( !indexExists || @@ -102,7 +103,7 @@ const brew: IPCBrew = { ]); (brew as any)._postIndexing(); - cacheDB_updateLastFullIndexJsTimestamp(); + cacheDB_updateLastFullIndexJsTimestamp("brew"); }, async indexOutdated(): Promise { diff --git a/src/renderer/preload/platform/macOS/brewCask.ts b/src/renderer/preload/platform/macOS/brewCask.ts index bb5fcd3..be88b63 100644 --- a/src/renderer/preload/platform/macOS/brewCask.ts +++ b/src/renderer/preload/platform/macOS/brewCask.ts @@ -167,10 +167,10 @@ const brewCask: IPCBrewCask = { } catch (e) {} const nowTime = new Date().getTime(); - const timeSinceIndexBuilt = - (nowTime - cacheDB_lastFullIndexJsTimestamp()) / 1000; + const lastFullIndexTime = cacheDB_lastFullIndexJsTimestamp("brew-cask"); + const secondsSinceIndexBuilt = (nowTime - lastFullIndexTime) / 1000; const indexTooOld = - timeSinceIndexBuilt > (await getFullIndexIntervalInSeconds()); + secondsSinceIndexBuilt > (await getFullIndexIntervalInSeconds()); if ( !indexExists || @@ -196,7 +196,7 @@ const brewCask: IPCBrewCask = { ]); (brewCask as any)._postIndexing(); - cacheDB_updateLastFullIndexJsTimestamp(); + cacheDB_updateLastFullIndexJsTimestamp("brew-cask"); }, async indexOutdated(): Promise { diff --git a/src/renderer/preload/shared/db/cacheDB.ts b/src/renderer/preload/shared/db/cacheDB.ts index d44c578..6dbd12c 100644 --- a/src/renderer/preload/shared/db/cacheDB.ts +++ b/src/renderer/preload/shared/db/cacheDB.ts @@ -43,7 +43,7 @@ export function cacheDB_addSchema(schema: string) { } type CacheDBMeta = { - lastFullIndexJsTimestamp?: number; + lastFullIndexJsTimestamp?: Record; }; function cacheDB_loadMeta(): CacheDBMeta { @@ -58,13 +58,24 @@ function cacheDB_saveMeta(meta: CacheDBMeta) { fs.writeFileSync(cacheMetaPath, JSON.stringify(meta)); } -export function cacheDB_lastFullIndexJsTimestamp(): number { - return cacheDB_loadMeta()?.lastFullIndexJsTimestamp ?? new Date().getTime(); +export function cacheDB_lastFullIndexJsTimestamp( + packageManagerKey: string +): number { + return ( + cacheDB_loadMeta()?.lastFullIndexJsTimestamp?.[packageManagerKey] ?? + new Date().getTime() + ); } -export function cacheDB_updateLastFullIndexJsTimestamp(): void { +export function cacheDB_updateLastFullIndexJsTimestamp( + packageManagerKey: string +): void { + const oldMeta = cacheDB_loadMeta(); cacheDB_saveMeta({ - ...cacheDB_loadMeta(), - lastFullIndexJsTimestamp: new Date().getTime(), + ...oldMeta, + lastFullIndexJsTimestamp: { + ...oldMeta.lastFullIndexJsTimestamp, + [packageManagerKey]: new Date().getTime(), + }, }); }