mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
[ContentCacheManager] skip writing of duplicate streams
This commit is contained in:
parent
b456ea726d
commit
bc1ed82c6c
1 changed files with 7 additions and 0 deletions
|
@ -20,13 +20,20 @@ async function update(contentDir, filePath) {
|
|||
const extractor = new PdfStreamsExtractor()
|
||||
const ranges = []
|
||||
const newRanges = []
|
||||
const seenHashes = new Set()
|
||||
for await (const chunk of stream) {
|
||||
const pdfStreams = extractor.consume(chunk)
|
||||
for (const pdfStream of pdfStreams) {
|
||||
if (pdfStream.end - pdfStream.start < MIN_CHUNK_SIZE) continue
|
||||
const hash = pdfStreamHash(pdfStream.buffers)
|
||||
|
||||
const range = { start: pdfStream.start, end: pdfStream.end, hash }
|
||||
ranges.push(range)
|
||||
|
||||
// Optimization: Skip writing of duplicate streams.
|
||||
if (seenHashes.has(hash)) continue
|
||||
seenHashes.add(hash)
|
||||
|
||||
if (await writePdfStream(contentDir, hash, pdfStream.buffers)) {
|
||||
newRanges.push(range)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue