Skip to content

Commit 35fdfed

Browse files
committed
Preserve cached Maia model when URL changes
Instead of deleting the cached model and forcing a ~93MB re-download when the source URL changes, update the stored URL in-place and return the existing cached data. The model binary is identical regardless of which URL served it. https://claude.ai/code/session_01T73Yphu4y2U3c3ctCcHVPf
1 parent f77f11d commit 35fdfed

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

src/lib/engine/storage.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,23 @@ export class MaiaModelStorage {
9595
return null
9696
}
9797

98-
// Check if URL matches (for cache invalidation)
98+
// If the URL changed but we still have cached data, keep the model
99+
// and update the stored URL so future loads hit the cache directly.
99100
if (modelData.url !== modelUrl) {
100-
console.log('Storage: Model URL changed, clearing old cache')
101+
console.log('Storage: Model URL changed, updating stored URL')
101102
console.log('Storage: Cached URL:', modelData.url)
102-
console.log('Storage: Requested URL:', modelUrl)
103-
await this.deleteModel()
104-
console.log(
105-
'Storage: Old cache cleared, model needs to be re-downloaded',
106-
)
107-
return null
103+
console.log('Storage: New URL:', modelUrl)
104+
try {
105+
const rwTx = db.transaction([this.storeName], 'readwrite')
106+
const rwStore = rwTx.objectStore(this.storeName)
107+
await new Promise<void>((resolve, reject) => {
108+
const req = rwStore.put({ ...modelData, url: modelUrl })
109+
req.onsuccess = () => resolve()
110+
req.onerror = () => reject(req.error)
111+
})
112+
} catch (e) {
113+
console.warn('Storage: Failed to update stored URL:', e)
114+
}
108115
}
109116

110117
console.log('Storage: Converting Blob to ArrayBuffer...')

0 commit comments

Comments
 (0)