chore: documentStructure database locking (#3254)

This commit is contained in:
Tom Moor
2022-03-18 08:59:11 -07:00
committed by GitHub
parent c98c397fa8
commit 5e655e42f6
7 changed files with 566 additions and 433 deletions

View File

@@ -6,6 +6,7 @@ import documentCreator from "@server/commands/documentCreator";
import documentImporter from "@server/commands/documentImporter";
import documentMover from "@server/commands/documentMover";
import documentPermanentDeleter from "@server/commands/documentPermanentDeleter";
import { sequelize } from "@server/database/sequelize";
import {
NotFoundError,
InvalidRequestError,
@@ -1041,28 +1042,11 @@ router.post("documents.update", auth(), async (ctx) => {
document.lastModifiedById = user.id;
const { collection } = document;
const changed = document.changed();
let transaction;
try {
transaction = await document.sequelize.transaction();
if (publish) {
await document.publish(user.id, {
transaction,
});
} else {
await document.save({
transaction,
});
}
await transaction.commit();
} catch (err) {
if (transaction) {
await transaction.rollback();
}
throw err;
if (publish) {
await document.publish(user.id);
} else {
await document.save();
}
if (publish) {
@@ -1154,14 +1138,21 @@ router.post("documents.move", auth(), async (ctx) => {
authorize(user, "update", parent);
}
const { documents, collections, collectionChanged } = await documentMover({
user,
document,
collectionId,
parentDocumentId,
index,
ip: ctx.request.ip,
});
const {
documents,
collections,
collectionChanged,
} = await sequelize.transaction(async (transaction) =>
documentMover({
user,
document,
collectionId,
parentDocumentId,
index,
ip: ctx.request.ip,
transaction,
})
);
ctx.body = {
data: {