mirror of
https://github.com/outline/outline.git
synced 2026-11-30 17:10:36 +03:00
perf: Load only ids when resolving membership user ids (#14275)
This commit is contained in:
1 parent
3967edc5d9
commit
e76f0dcf8e
3 files changed
+48
No files matched your search
@@ -644,6 +644,7 @@ class Collection extends ParanoidModel<
|
||||
) {
|
||||
const collection = await this.scope("withAllMemberships").findOne({
|
||||
where: { id: collectionId },
|
||||
attributes: ["id"],
|
||||
include: [
|
||||
{
|
||||
association: "memberships",
|
||||
|
||||
@@ -440,6 +440,52 @@ describe("#findAllParentDocumentIds", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("#membershipUserIds", () => {
|
||||
it("should return unique users with direct and group memberships", async () => {
|
||||
const team = await buildTeam();
|
||||
const owner = await buildUser({ teamId: team.id });
|
||||
const [direct, grouped, both] = await Promise.all([
|
||||
buildUser({ teamId: team.id }),
|
||||
buildUser({ teamId: team.id }),
|
||||
buildUser({ teamId: team.id }),
|
||||
]);
|
||||
const document = await buildDocument({
|
||||
teamId: team.id,
|
||||
userId: owner.id,
|
||||
});
|
||||
const group = await buildGroup({ teamId: team.id });
|
||||
await group.$add("user", grouped, { through: { createdById: owner.id } });
|
||||
await group.$add("user", both, { through: { createdById: owner.id } });
|
||||
await GroupMembership.create({
|
||||
createdById: owner.id,
|
||||
groupId: group.id,
|
||||
documentId: document.id,
|
||||
permission: DocumentPermission.Read,
|
||||
});
|
||||
await UserMembership.create({
|
||||
createdById: owner.id,
|
||||
documentId: document.id,
|
||||
userId: direct.id,
|
||||
permission: DocumentPermission.ReadWrite,
|
||||
});
|
||||
await UserMembership.create({
|
||||
createdById: owner.id,
|
||||
documentId: document.id,
|
||||
userId: both.id,
|
||||
permission: DocumentPermission.Read,
|
||||
});
|
||||
|
||||
const userIds = await Document.membershipUserIds(document.id);
|
||||
expect(userIds.sort()).toEqual([direct.id, grouped.id, both.id].sort());
|
||||
|
||||
const writerIds = await Document.membershipUserIds(
|
||||
document.id,
|
||||
DocumentPermission.ReadWrite
|
||||
);
|
||||
expect(writerIds).toEqual([direct.id]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#membershipDocumentIds", () => {
|
||||
it("should return empty array when the user has no document memberships", async () => {
|
||||
const user = await buildUser();
|
||||
|
||||
@@ -780,6 +780,7 @@ class Document extends ArchivableModel<
|
||||
) {
|
||||
const document = await this.scope("withAllMemberships").findOne({
|
||||
where: { id: documentId },
|
||||
attributes: ["id"],
|
||||
include: [
|
||||
{
|
||||
association: "memberships",
|
||||
|
||||
Reference in new issue
Block a user