perf: Reduce connections required for findByPk (#13214)

This commit is contained in:
Tom Moor
2026-07-31 13:19:40 -04:00
committed by GitHub
parent 17accab55a
commit aae3e4b81a
2 changed files with 22 additions and 24 deletions
-2
View File
@@ -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,