Revert "clear rootDoc_id when deleting doc, reset on compiles if invalid"

This reverts commit 539982adbf55014400f4aff94195e7f567cda676.

GitOrigin-RevId: 7acba5876581044a08d6deb4767a4a2196dcb765
This commit is contained in:
Ersun Warncke
2020-02-05 08:49:04 -04:00
committed by Copybot
parent d8b627f59b
commit 76a6c399e3
5 changed files with 21 additions and 83 deletions

View File

@@ -314,9 +314,8 @@ async function moveEntity(projectId, entityId, destFolderId, entityType) {
async function deleteEntity(projectId, entityId, entityType, callback) {
const project = await ProjectGetter.promises.getProjectWithoutLock(
projectId,
{ name: true, rootFolder: true, overleaf: true, rootDoc_id: true }
{ name: true, rootFolder: true, overleaf: true }
)
const deleteRootDoc = project.rootDoc_id && entityId && project.rootDoc_id.toString() === entityId.toString()
const { element: entity, path } = await ProjectLocator.promises.findElement({
project,
element_id: entityId,
@@ -326,8 +325,7 @@ async function deleteEntity(projectId, entityId, entityType, callback) {
Project,
projectId,
path.mongo,
entityId,
deleteRootDoc
entityId
)
return { entity, path, projectBeforeDeletion: project, newProject }
}
@@ -416,18 +414,19 @@ async function _insertDeletedFileReference(projectId, fileRef) {
).exec()
}
async function _removeElementFromMongoArray(model, modelId, path, elementId, deleteRootDoc=false) {
async function _removeElementFromMongoArray(model, modelId, path, elementId) {
const nonArrayPath = path.slice(0, path.lastIndexOf('.'))
const options = { new: true }
const query = { _id: modelId }
const update = {
$pull: { [nonArrayPath]: { _id: elementId } },
$inc: { version: 1 }
}
if (deleteRootDoc) {
update.$unset = { rootDoc_id: 1 }
}
return model.findOneAndUpdate(query, update, options).exec()
const newDoc = model
.findOneAndUpdate(
{ _id: modelId },
{
$pull: { [nonArrayPath]: { _id: elementId } },
$inc: { version: 1 }
},
{ new: true }
)
.exec()
return newDoc
}
function _countElements(project) {