Skip to content

Commit

Permalink
fix: add cleaner cron impl
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <tukon479@gmail.com>
  • Loading branch information
Innei committed Nov 11, 2024
1 parent 0ce6546 commit faae74b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
16 changes: 11 additions & 5 deletions apps/main/src/lib/cleaner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ const getCachedFilesRecursive = async (dir: string, result: string[] = []) => {
}

let timer: any = null

export const clearCacheCronJob = () => {
if (timer) {
timer = clearInterval(timer)
Expand Down Expand Up @@ -121,11 +122,16 @@ export const clearCacheCronJob = () => {

let cleanedSize = 0
for (const file of files) {
const fileSize = statSync(file).size
cleanedSize += fileSize
if (cleanedSize >= shouldCleanSize) {
logger.info(`Cleaned ${cleanedSize} bytes cache`)
break
try {
const fileSize = statSync(file).size
await fsp.rm(file, { force: true })
cleanedSize += fileSize
if (cleanedSize >= shouldCleanSize) {
logger.info(`Cleaned ${cleanedSize} bytes cache`)
break
}
} catch (error) {
logger.error(`Failed to delete cache file ${file}:`, error)
}
}
}
Expand Down
1 change: 1 addition & 0 deletions apps/renderer/src/modules/settings/tabs/data-control.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ const AppCacheLimit = () => {
const byteSize = (await tipcClient?.getCacheSize()) ?? 0
return Math.round(byteSize / 1024 / 1024)
},
refetchOnMount: "always",
})
const {
data: cacheLimit,
Expand Down

0 comments on commit faae74b

Please sign in to comment.