mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-15 06:33:55 +01:00
[track-changes] Ignore duplicated packs when zipping SL history (#8353)
* [track-changes] Ignore duplicated packs when zipping SL history * Fix incorrect `ObjectId` import in unit tests GitOrigin-RevId: 165fcaa0c7bc57d383d01eedaf6dd3b078aff2aa
This commit is contained in:
@@ -11,6 +11,7 @@ const stream = require('stream')
|
||||
const fs = require('fs')
|
||||
const os = require('os')
|
||||
const Path = require('path')
|
||||
const { packsAreDuplicated } = require('./util/PackUtils')
|
||||
|
||||
const streamPipeline = util.promisify(stream.pipeline)
|
||||
|
||||
@@ -85,8 +86,13 @@ async function rewindDoc(projectId, docId, zipfile) {
|
||||
let content = latestContent
|
||||
let v = version
|
||||
let update = lastUpdate
|
||||
let previousUpdate = null
|
||||
|
||||
while (update) {
|
||||
if (packsAreDuplicated(update, previousUpdate)) {
|
||||
continue
|
||||
}
|
||||
|
||||
const updatePath = `${id}/updates/${update.v}`
|
||||
|
||||
zipfile.addBuffer(Buffer.from(JSON.stringify(update)), updatePath, {
|
||||
@@ -107,6 +113,7 @@ async function rewindDoc(projectId, docId, zipfile) {
|
||||
ts: update.meta.start_ts,
|
||||
doc_length: content.length,
|
||||
})
|
||||
previousUpdate = update
|
||||
update = await getUpdate()
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
const _ = require('lodash')
|
||||
|
||||
/**
|
||||
* Compares a deep equality of Packs excluding _id
|
||||
*/
|
||||
function packsAreDuplicated(pack1, pack2) {
|
||||
return Boolean(
|
||||
pack1 &&
|
||||
pack2 &&
|
||||
pack1.v === pack2.v &&
|
||||
_.isEqual(pack1.meta, pack2.meta) &&
|
||||
_.isEqual(pack1.op, pack2.op)
|
||||
)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
packsAreDuplicated,
|
||||
}
|
||||
Reference in New Issue
Block a user