Explorar o código

Merge pull request #9723 from overleaf/bg-log-large-docs-in-docstore-archive

warn about oversized docs in docstore archiving

GitOrigin-RevId: 296a49b37b7f6733ef33f682ae40a8d3d478d9e8
Brian Gough %!s(int64=3) %!d(string=hai) anos
pai
achega
53d2074315

+ 16 - 0
services/docstore/app/js/DocArchiveManager.js

@@ -9,6 +9,9 @@ const RangeManager = require('./RangeManager')
 const PersistorManager = require('./PersistorManager')
 const PersistorManager = require('./PersistorManager')
 const pMap = require('p-map')
 const pMap = require('p-map')
 
 
+const Bson = require('bson')
+const BSON = new Bson()
+
 const PARALLEL_JOBS = Settings.parallelArchiveJobs
 const PARALLEL_JOBS = Settings.parallelArchiveJobs
 const UN_ARCHIVE_BATCH_SIZE = Settings.unArchiveBatchSize
 const UN_ARCHIVE_BATCH_SIZE = Settings.unArchiveBatchSize
 
 
@@ -55,6 +58,19 @@ async function archiveDoc(projectId, docId) {
     throw new Error('doc has no lines')
     throw new Error('doc has no lines')
   }
   }
 
 
+  // warn about any oversized docs already in mongo
+  const linesSize = BSON.calculateObjectSize(doc.lines || {})
+  const rangesSize = BSON.calculateObjectSize(doc.ranges || {})
+  if (
+    linesSize > Settings.max_doc_length ||
+    rangesSize > Settings.max_doc_length
+  ) {
+    logger.warn(
+      { project_id: projectId, doc_id: doc._id, linesSize, rangesSize },
+      'large doc found when archiving project'
+    )
+  }
+
   const json = JSON.stringify({
   const json = JSON.stringify({
     lines: doc.lines,
     lines: doc.lines,
     ranges: doc.ranges,
     ranges: doc.ranges,

+ 1 - 0
services/docstore/package.json

@@ -23,6 +23,7 @@
     "@overleaf/settings": "^3.0.0",
     "@overleaf/settings": "^3.0.0",
     "async": "^3.2.2",
     "async": "^3.2.2",
     "body-parser": "^1.19.0",
     "body-parser": "^1.19.0",
+    "bson": "^1.1.4",
     "bunyan": "^1.8.15",
     "bunyan": "^1.8.15",
     "celebrate": "^13.0.4",
     "celebrate": "^13.0.4",
     "express": "^4.17.1",
     "express": "^4.17.1",