added function to get project with only folders for quicker adding of files to large projects

This commit is contained in:
Henry Oswald 2015-10-21 16:56:06 +01:00
parent 885915916a
commit 1c91de0395
4 changed files with 48 additions and 2 deletions

View file

@ -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)->

View file

@ -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)

View file

@ -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

View file

@ -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 = []