From 40704b486e52320141580e3b78a33cd8aa32e527 Mon Sep 17 00:00:00 2001 From: James Allen Date: Fri, 28 Aug 2015 16:51:52 +0100 Subject: [PATCH] Don't lock up on very long lined documents --- .../coffee/Features/Project/ProjectRootDocManager.coffee | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/services/web/app/coffee/Features/Project/ProjectRootDocManager.coffee b/services/web/app/coffee/Features/Project/ProjectRootDocManager.coffee index da2743d661..a6f429dca2 100644 --- a/services/web/app/coffee/Features/Project/ProjectRootDocManager.coffee +++ b/services/web/app/coffee/Features/Project/ProjectRootDocManager.coffee @@ -15,8 +15,12 @@ module.exports = ProjectRootDocManager = return (cb)-> rootDocId = null for line in doc.lines || [] - match = line.match /(.*)\\documentclass/ # no lookbehind in js regexp :( - isRootDoc = Path.extname(path).match(/\.R?tex$/) and match and !match[1].match /%/ + # We've had problems with this regex locking up CPU. + # Previously /.*\\documentclass/ would totally lock up on lines of 500kb (data text files :() + # This regex will only look from the start of the line, including whitespace so will return quickly + # regardless of line length. + match = line.match /^\s*\\documentclass/ + isRootDoc = Path.extname(path).match(/\.R?tex$/) and match if isRootDoc rootDocId = doc?._id cb(rootDocId)