mirror of
https://github.com/outline/outline.git
synced 2026-08-03 13:27:25 +03:00
perf: Reduce connections required for findByPk (#13214)
This commit is contained in:
@@ -200,7 +200,6 @@ interface QueryGeneratorWithWhere {
|
||||
userId,
|
||||
},
|
||||
required: false,
|
||||
separate: true,
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -228,7 +227,6 @@ interface QueryGeneratorWithWhere {
|
||||
userId,
|
||||
},
|
||||
required: false,
|
||||
separate: true,
|
||||
},
|
||||
{
|
||||
association: "groupMemberships",
|
||||
|
||||
@@ -177,28 +177,28 @@ router.get(
|
||||
return;
|
||||
}
|
||||
|
||||
const [documentSubscription, document, user] = await Promise.all([
|
||||
Subscription.findOne({
|
||||
where: {
|
||||
userId,
|
||||
documentId,
|
||||
},
|
||||
lock: Transaction.LOCK.UPDATE,
|
||||
transaction,
|
||||
}),
|
||||
Document.unscoped().findOne({
|
||||
attributes: ["collectionId"],
|
||||
where: {
|
||||
id: documentId,
|
||||
},
|
||||
paranoid: false,
|
||||
transaction,
|
||||
}),
|
||||
User.scope("withTeam").findByPk(userId, {
|
||||
rejectOnEmpty: true,
|
||||
transaction,
|
||||
}),
|
||||
]);
|
||||
// Queries within a transaction share a single connection, so they are run
|
||||
// sequentially rather than with Promise.all.
|
||||
const documentSubscription = await Subscription.findOne({
|
||||
where: {
|
||||
userId,
|
||||
documentId,
|
||||
},
|
||||
lock: Transaction.LOCK.UPDATE,
|
||||
transaction,
|
||||
});
|
||||
const document = await Document.unscoped().findOne({
|
||||
attributes: ["collectionId"],
|
||||
where: {
|
||||
id: documentId,
|
||||
},
|
||||
paranoid: false,
|
||||
transaction,
|
||||
});
|
||||
const user = await User.scope("withTeam").findByPk(userId, {
|
||||
rejectOnEmpty: true,
|
||||
transaction,
|
||||
});
|
||||
|
||||
const context = createContext({
|
||||
user,
|
||||
|
||||
Reference in New Issue
Block a user