perf: use findAll for querying document collaborators (#7697)

* perf: use findAll for querying document collaborators

* remove unnecessary compact
This commit is contained in:
Hemachandar
2024-09-29 22:13:07 +05:30
committed by GitHub
parent 91c2f60827
commit 21adfdd1bf
+8 -9
View File
@@ -807,15 +807,14 @@ class Document extends ParanoidModel<
* @param options FindOptions
* @returns A promise that resolve to a list of users
*/
collaborators = async (options?: FindOptions<User>): Promise<User[]> => {
const users = await Promise.all(
this.collaboratorIds.map((collaboratorId) =>
User.findByPk(collaboratorId, options)
)
);
return compact(users);
};
collaborators = async (options?: FindOptions<User>): Promise<User[]> =>
await User.findAll({
...options,
where: {
...options?.where,
id: this.collaboratorIds,
},
});
/**
* Find all of the child documents for this document