From bd4d9b966d96b49efa7c15de47af6271528acd14 Mon Sep 17 00:00:00 2001 From: Vanilagy <1696106+Vanilagy@users.noreply.github.com> Date: Sat, 30 Aug 2025 15:18:52 +0200 Subject: [PATCH] Fix cache bug --- src/source.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/source.ts b/src/source.ts index 9737fd6..568ff65 100644 --- a/src/source.ts +++ b/src/source.ts @@ -1057,6 +1057,8 @@ class ReadOrchestrator { joined.set(previous.bytes, 0); joined.set(entry.bytes, entry.start - previous.start); + this.currentCacheSize += entry.end - previous.end; + previous.bytes = joined; previous.view = toDataView(joined); previous.end = entry.end; @@ -1064,8 +1066,6 @@ class ReadOrchestrator { // Do the rest of the logic with the previous entry instead insertionIndex--; entry = previous; - - this.currentCacheSize += entry.end - previous.end; } else { this.cache.splice(insertionIndex, 0, entry); this.currentCacheSize += entry.bytes.length; @@ -1095,13 +1095,13 @@ class ReadOrchestrator { joined.set(entry.bytes, 0); joined.set(next.bytes, next.start - entry.start); + this.currentCacheSize -= entry.end - next.start; // Subtract the overlap + entry.bytes = joined; entry.view = toDataView(joined); entry.end = next.end; this.cache.splice(i, 1); - this.currentCacheSize -= entry.end - next.start; - break; // After the join case, we're done: the next entry cannot possibly overlap with the inserted one. }