From 1c91de0395e03d4e80b7aaf51e376301e3d7baba Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Wed, 21 Oct 2015 16:56:06 +0100 Subject: [PATCH] added function to get project with only folders for quicker adding of files to large projects --- .../Project/ProjectEntityHandler.coffee | 2 +- .../Features/Project/ProjectGetter.coffee | 8 +++++ .../Project/ProjectEntityHandlerTests.coffee | 5 ++- .../coffee/Project/ProjectGetterTests.coffee | 35 +++++++++++++++++++ 4 files changed, 48 insertions(+), 2 deletions(-) diff --git a/services/web/app/coffee/Features/Project/ProjectEntityHandler.coffee b/services/web/app/coffee/Features/Project/ProjectEntityHandler.coffee index d7f2f51ef8..f78a638c14 100644 --- a/services/web/app/coffee/Features/Project/ProjectEntityHandler.coffee +++ b/services/web/app/coffee/Features/Project/ProjectEntityHandler.coffee @@ -140,7 +140,7 @@ module.exports = ProjectEntityHandler = ProjectEntityHandler.addDoc project_id, null, name, lines, callback addFile: (project_or_id, folder_id, fileName, path, callback = (error, fileRef, folder_id) ->)-> - Project.getProject project_or_id, "", (err, project) -> + ProjectGetter.getProjectWithOnlyFolders project_or_id, (err, project) -> logger.log project_id: project._id, folder_id: folder_id, file_name: fileName, path:path, "adding file" return callback(err) if err? confirmFolder project, folder_id, (folder_id)-> diff --git a/services/web/app/coffee/Features/Project/ProjectGetter.coffee b/services/web/app/coffee/Features/Project/ProjectGetter.coffee index 6d756c638e..129ff831dc 100644 --- a/services/web/app/coffee/Features/Project/ProjectGetter.coffee +++ b/services/web/app/coffee/Features/Project/ProjectGetter.coffee @@ -13,6 +13,14 @@ module.exports = ProjectGetter = db.projects.find _id: ObjectId(project_id.toString()), excludes, (error, projects = []) -> callback error, projects[0] + getProjectWithOnlyFolders: (project_id, callback=(error, project) ->) -> + excludes = {} + for i in [1..@EXCLUDE_DEPTH] + excludes["rootFolder#{Array(i).join(".folder")}.docs"] = 0 + excludes["rootFolder#{Array(i).join(".folder")}.fileRefs"] = 0 + db.projects.find _id: ObjectId(project_id.toString()), excludes, (error, projects = []) -> + callback error, projects[0] + getProject: (query, projection, callback = (error, project) ->) -> if typeof query == "string" query = _id: ObjectId(query) diff --git a/services/web/test/UnitTests/coffee/Project/ProjectEntityHandlerTests.coffee b/services/web/test/UnitTests/coffee/Project/ProjectEntityHandlerTests.coffee index c25b126e82..16c27bf32f 100644 --- a/services/web/test/UnitTests/coffee/Project/ProjectEntityHandlerTests.coffee +++ b/services/web/test/UnitTests/coffee/Project/ProjectEntityHandlerTests.coffee @@ -55,6 +55,8 @@ describe 'ProjectEntityHandler', -> @ProjectModel.findById = (project_id, callback)=> callback(null, @project) @ProjectModel.getProject = (project_id, fields, callback)=> callback(null, @project) + @ProjectGetter = + getProjectWithOnlyFolders : (project_id, callback)=> callback(null, @project) @ProjectModel.putElement = (project_id, folder_id, doc, type, callback)-> callback(null, {path:{fileSystem:"somehintg"}}) @projectUpdater = markAsUpdated:sinon.stub() @ProjectEntityHandler = SandboxedModule.require modulePath, requires: @@ -69,7 +71,7 @@ describe 'ProjectEntityHandler', -> '../Docstore/DocstoreManager': @DocstoreManager = {} 'logger-sharelatex': @logger = {log:sinon.stub(), error: sinon.stub()} './ProjectUpdateHandler': @projectUpdater - "./ProjectGetter": @ProjectGetter = {} + "./ProjectGetter": @ProjectGetter describe 'mkdirp', -> @@ -503,6 +505,7 @@ describe 'ProjectEntityHandler', -> @ProjectModel.putElement = (project_id, folder_id, doc, type, callback)-> callback(null, {path:{fileSystem:opts.path}}) @tpdsUpdateSender.addFile = (options)=> + console.log @project.name, options.project_name options.project_id.should.equal project_id options.path.should.equal opts.path options.project_name.should.equal @project.name diff --git a/services/web/test/UnitTests/coffee/Project/ProjectGetterTests.coffee b/services/web/test/UnitTests/coffee/Project/ProjectGetterTests.coffee index e2c533f804..b8f1480be6 100644 --- a/services/web/test/UnitTests/coffee/Project/ProjectGetterTests.coffee +++ b/services/web/test/UnitTests/coffee/Project/ProjectGetterTests.coffee @@ -43,6 +43,41 @@ describe "ProjectGetter", -> it "should call the callback with the project", -> @callback.calledWith(null, @project).should.equal true + describe "getProjectWithOnlyFolders", -> + beforeEach -> + @project = + _id: @project_id = "0123456789abcd9876543210" + @db.projects.find = sinon.stub().callsArgWith(2, null, [@project]) + @ProjectGetter.getProjectWithOnlyFolders @project_id, @callback + + it "should call find with the project id", -> + @db.projects.find.calledWith(_id: ObjectId(@project_id)).should.equal true + + it "should exclude the docs and files lines", -> + excludes = + "rootFolder.docs": 0 + "rootFolder.fileRefs": 0 + "rootFolder.folder.docs": 0 + "rootFolder.folder.fileRefs": 0 + "rootFolder.folder.folder.docs": 0 + "rootFolder.folder.folder.fileRefs": 0 + "rootFolder.folder.folder.folder.docs": 0 + "rootFolder.folder.folder.folder.fileRefs": 0 + "rootFolder.folder.folder.folder.folder.docs": 0 + "rootFolder.folder.folder.folder.folder.fileRefs": 0 + "rootFolder.folder.folder.folder.folder.folder.docs": 0 + "rootFolder.folder.folder.folder.folder.folder.fileRefs": 0 + "rootFolder.folder.folder.folder.folder.folder.folder.docs": 0 + "rootFolder.folder.folder.folder.folder.folder.folder.fileRefs": 0 + "rootFolder.folder.folder.folder.folder.folder.folder.folder.docs": 0 + "rootFolder.folder.folder.folder.folder.folder.folder.folder.fileRefs": 0 + @db.projects.find.calledWith(sinon.match.any, excludes) + .should.equal true + + it "should call the callback with the project", -> + @callback.calledWith(null, @project).should.equal true + + describe "populateProjectWithUsers", -> beforeEach -> @users = []