mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-29 14:03:07 +00:00
865a973426
[docupdater] use more accurate doc size check GitOrigin-RevId: f66d68a7f7fdc127cc31539abdcab65549823d02
31 lines
1.2 KiB
JavaScript
31 lines
1.2 KiB
JavaScript
module.exports = {
|
|
// compute the total size of the document in chararacters, including newlines
|
|
getTotalSizeOfLines(lines) {
|
|
let size = 0
|
|
for (const line of lines) {
|
|
size += line.length + 1 // include the newline
|
|
}
|
|
return size
|
|
},
|
|
|
|
// check whether the total size of the document in characters exceeds the
|
|
// maxDocLength.
|
|
//
|
|
// The estimated size should be an upper bound on the true size, typically
|
|
// it will be the size of the JSON.stringified array of lines. If the
|
|
// estimated size is less than the maxDocLength then we know that the total
|
|
// size of lines will also be less than maxDocLength.
|
|
docIsTooLarge(estimatedSize, lines, maxDocLength) {
|
|
if (estimatedSize <= maxDocLength) {
|
|
return false // definitely under the limit, no need to calculate the total size
|
|
}
|
|
// calculate the total size, bailing out early if the size limit is reached
|
|
let size = 0
|
|
for (const line of lines) {
|
|
size += line.length + 1 // include the newline
|
|
if (size > maxDocLength) return true
|
|
}
|
|
// since we didn't hit the limit in the loop, the document is within the allowed length
|
|
return false
|
|
},
|
|
}
|