allow querying folders from existing project

avoid loading the project unnecessarily
This commit is contained in:
Brian Gough 2017-08-01 14:39:02 +01:00
parent 7a39eeb2ea
commit 66cd6ada14

View file

@ -31,8 +31,7 @@ module.exports = ProjectEntityHandler =
ProjectGetter.getProjectWithoutDocLines project_id, (err, project) ->
return callback(err) if err?
return callback("no project") if !project?
processFolder "/", project.rootFolder[0]
callback null, folders
ProjectEntityHandler.getAllFoldersFromProject project, callback
getAllDocs: (project_id, callback) ->
logger.log project_id:project_id, "getting all docs for project"
@ -74,6 +73,29 @@ module.exports = ProjectEntityHandler =
files[path.join(folderPath, file.name)] = file
callback null, files
getAllFoldersFromProject: (project, callback) ->
folders = {}
processFolder = (basePath, folder) ->
folders[basePath] = folder
for childFolder in (folder.folders or [])
if childFolder.name?
processFolder path.join(basePath, childFolder.name), childFolder
processFolder "/", project.rootFolder[0]
callback null, folders
getAllDocPathsFromProject: (project, callback) ->
logger.log project:project, "getting all docs for project"
@getAllFoldersFromProject project, (err, folders = {}) ->
return callback(err) if err?
docPath = {}
for folderPath, folder of folders
for doc in (folder.docs or [])
console.log "PATH", path.join(folderPath, doc.name), doc._id, doc.name
docPath[doc._id] = path.join(folderPath, doc.name)
logger.log count:_.keys(docPath).length, project_id:project._id, "returning docPaths for project"
callback null, docPath
flushProjectToThirdPartyDataStore: (project_id, callback) ->
self = @
logger.log project_id:project_id, "flushing project to tpds"