diff --git a/js/ui.js b/js/ui.js index 02f6fb47..2aa5e40c 100644 --- a/js/ui.js +++ b/js/ui.js @@ -1476,7 +1476,7 @@ window.onload = async () => { speciesThreshold: config.speciesThreshold }); loadModel(); - worker.postMessage({ action: 'clear-cache' }) + //worker.postMessage({ action: 'clear-cache' }) // New users - show the tour if (!config.seenTour) { setTimeout(prepTour, 2000) @@ -2191,7 +2191,7 @@ speciesThreshold.addEventListener('change', () =>{ worker.postMessage({ action: 'update-list', list: config.list }) }) -const loadModel = () => { +const loadModel = ({clearCache = true} = {}) => { t0_warmup = Date.now(); worker.postMessage({ action: 'load-model', @@ -2200,7 +2200,8 @@ const loadModel = () => { batchSize: config[config.backend].batchSize, warmup: config.warmup, threads: config[config.backend].threads, - backend: config.backend + backend: config.backend, + clearCache: clearCache }); } @@ -2253,7 +2254,7 @@ const handleBackendChange = (e) => { updatePrefs(); // restart wavesurfer regions to set new maxLength initRegion(); - loadModel(); + loadModel({clearCache: false}); } const backend = document.getElementsByName('backend'); @@ -3472,7 +3473,7 @@ batchSizeSlider.addEventListener('input', (e) => { }) batchSizeSlider.addEventListener('change', (e) => { config[config.backend].batchSize = BATCH_SIZE_LIST[e.target.value]; - loadModel(); + loadModel({clearCache: false}); updatePrefs(); // Reset region maxLength initRegion(); @@ -3960,7 +3961,7 @@ ThreadSlider.addEventListener('input', () => { }); ThreadSlider.addEventListener('change', () => { config[config.backend].threads = ThreadSlider.valueAsNumber; - loadModel(); + loadModel({clearCache: false}); updatePrefs(); }); diff --git a/js/worker.js b/js/worker.js index 7ac82179..89d5b4e4 100644 --- a/js/worker.js +++ b/js/worker.js @@ -204,7 +204,6 @@ const clearCache = async (fileCache, sizeLimitInGB) => { const requiredSpace = sizeLimitInGB * 1024 ** 3; // If Full, clear at least 25% of cache, so we're not doing this too frequently if (size > requiredSpace) { - // while (size > requiredSpace && canBeRemovedFromCache.length) { while (canBeRemovedFromCache.length > 1) { const file = canBeRemovedFromCache.shift(); const proxy = metadata[file].proxy; @@ -251,9 +250,10 @@ break; case "chart": {await onChartRequest(args); break; } - case "clear-cache": {CACHE_LOCATION = p.join(TEMP, "chirpity"); -fs.existsSync(CACHE_LOCATION) || fs.mkdirSync(CACHE_LOCATION); -await clearCache(CACHE_LOCATION, 0); + case "clear-cache": { + CACHE_LOCATION = p.join(TEMP, "chirpity"); + fs.existsSync(CACHE_LOCATION) || fs.mkdirSync(CACHE_LOCATION); + await clearCache(CACHE_LOCATION, 0); break; } case "convert-dataset": {convertSpecsFromExistingSpecs(); @@ -314,7 +314,12 @@ break; event: "spawning" }); sampleRate = args.model === "v2.4" ? 48_000 : 24_000; - + // Since models have different sample rates, we need to clear the cache of + // files that have been resampled for a different model, and reset metadata + CACHE_LOCATION = p.join(TEMP, "chirpity"); + DEBUG && console.log('clear cache', args.clearCache, 'location', CACHE_LOCATION) + args.clearCache && ipcRenderer.invoke('clear-cache', CACHE_LOCATION) + metadata = {} BATCH_SIZE = parseInt(args.batchSize); setAudioContext(sampleRate); memoryDB = undefined; diff --git a/main.js b/main.js index d65192cd..428ca3a7 100644 --- a/main.js +++ b/main.js @@ -489,3 +489,9 @@ ipcMain.handle('saveFile', (event, arg) => { }); mainWindow.webContents.send('saveFile', { message: 'file saved!' }); }); + +ipcMain.handle('clear-cache', (event, filePath) => { + // console.log("cache location:", event, filePath); + // return + clearCache(filePath) +}) \ No newline at end of file diff --git a/preload.js b/preload.js index 6bcc1e01..20b943da 100644 --- a/preload.js +++ b/preload.js @@ -51,7 +51,7 @@ contextBridge.exposeInMainWorld('electron', { getPath: () => ipcRenderer.invoke('getPath'), getTemp: () => ipcRenderer.invoke('getTemp'), getVersion: () => ipcRenderer.invoke('getVersion'), - getAudio: () => ipcRenderer.invoke('getAudio'), + getAudio: () => ipcRenderer.invoke('getAudio') }); contextBridge.exposeInMainWorld('module', {