From a3dbb16e50535c83f7ef48cafa8f460720d3a579 Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Tue, 13 Jun 2017 11:15:26 +0100 Subject: [PATCH] Flush project before getting all project labels --- .../app/coffee/Features/Labels/LabelsHandler.coffee | 12 ++++++------ .../coffee/Labels/LabelsHandlerTests.coffee | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/services/web/app/coffee/Features/Labels/LabelsHandler.coffee b/services/web/app/coffee/Features/Labels/LabelsHandler.coffee index a32390ab72..1d4cc013d5 100644 --- a/services/web/app/coffee/Features/Labels/LabelsHandler.coffee +++ b/services/web/app/coffee/Features/Labels/LabelsHandler.coffee @@ -8,16 +8,16 @@ module.exports = LabelsHandler = /\\label\{([^\}\n\\]{0,80})\}/g getAllLabelsForProject: (projectId, callback=(err, projectLabels)->) -> - ProjectEntityHandler.getAllDocs projectId, (err, docs) -> + DocumentUpdaterHandler.flushProjectToMongo projectId, (err) -> if err? return callback(err) - projectLabels = LabelsHandler.extractLabelsFromProjectDocs docs - callback(null, projectLabels) + ProjectEntityHandler.getAllDocs projectId, (err, docs) -> + if err? + return callback(err) + projectLabels = LabelsHandler.extractLabelsFromProjectDocs docs + callback(null, projectLabels) getLabelsForDoc: (projectId, docId, callback=(err, docLabels)->) -> - # Flush doc first, because this action is often performed while - # a document is being edited by the client. By contrast, - # `getAllLabelsForProject` is called only when a project/editor is loaded DocumentUpdaterHandler.flushDocToMongo projectId, docId, (err) -> if err? return callback(err) diff --git a/services/web/test/UnitTests/coffee/Labels/LabelsHandlerTests.coffee b/services/web/test/UnitTests/coffee/Labels/LabelsHandlerTests.coffee index 1757a32bbe..50ce418e63 100644 --- a/services/web/test/UnitTests/coffee/Labels/LabelsHandlerTests.coffee +++ b/services/web/test/UnitTests/coffee/Labels/LabelsHandlerTests.coffee @@ -105,6 +105,7 @@ describe 'LabelsHandler', -> 'doc_one': {lines: ['\\label{aaa}']} } @fakeLabels = ['aaa'] + @DocumentUpdaterHandler.flushProjectToMongo = sinon.stub().callsArgWith(1, null) @ProjectEntityHandler.getAllDocs = sinon.stub().callsArgWith(1, null, @fakeDocs) @LabelsHandler.extractLabelsFromProjectDocs = sinon.stub().returns(@fakeLabels) @call = (callback) =>