@@ -160,6 +160,15 @@ async function _fetchAndDecryptIndex(owner, repo, indexSha, password, token) {
160160}
161161
162162async function _loadFromShardManifest ( manifest , owner , repo , password , token , progress ) {
163+ // 0) Check if the full merged DB is already cached for this commit SHA.
164+ // If the data branch hasn't moved, we can skip ALL shard loading.
165+ var mergedKey = "merged:" + manifest . commitSha ;
166+ var cachedMerged = await _idbGet ( mergedKey ) ;
167+ if ( cachedMerged ) {
168+ await ICS . db . initDB ( cachedMerged ) ;
169+ return ;
170+ }
171+
163172 // 1) Load index: check if index SHA matches cached → reuse decrypted JSON;
164173 // otherwise fetch + decrypt + cache for next time.
165174 var cachedIndexSha = null ;
@@ -193,6 +202,13 @@ async function _loadFromShardManifest(manifest, owner, repo, password, token, pr
193202 var shardBytes = await _loadShard ( owner , repo , entry , password , token ) ;
194203 await ICS . db . attachShard ( shardBytes ) ;
195204 }
205+
206+ // 3) Cache the merged DB in IndexedDB so next load with the same commit
207+ // SHA skips EVERYTHING — no index fetch, no shard iteration, no merge.
208+ try {
209+ var merged = ICS . db . exportDB ( ) ;
210+ await _idbPut ( mergedKey , merged ) ;
211+ } catch ( e ) { /* non-critical — silently skip */ }
196212}
197213
198214async function _loadFromLegacyBlob ( manifest , owner , repo , secrets , token ) {
0 commit comments