I have a question regarding the implementation of getAllParentsForFolder in queries.ts. Currently, it uses a while loop to retrieve all parent folders. I'm wondering if this approach could impact performance, especially when dealing with deeply nested structures.
getAllParentsForFolder: async function (folderId: number) {
const parents = [];
let currentId: number | null = folderId;
while (currentId !== null) {
const folder = await db
.selectDistinct()
.from(foldersSchema)
.where(eq(foldersSchema.id, currentId));
if (!folder[0]) {
throw new Error("Parent folder not found");
}
parents.unshift(folder[0]);
currentId = folder[0]?.parent;
}
return parents;
},
Is there a more efficient way to achieve the same result?
Is SQL CTE better for this type of query by using sql operator? Ex.QUERIES-WITH-RECURSIVE
I’d appreciate any insights or recommendations. Thanks!
I have a question regarding the implementation of getAllParentsForFolder in queries.ts. Currently, it uses a while loop to retrieve all parent folders. I'm wondering if this approach could impact performance, especially when dealing with deeply nested structures.
Is there a more efficient way to achieve the same result?
Is SQL CTE better for this type of query by using
sqloperator? Ex.QUERIES-WITH-RECURSIVEI’d appreciate any insights or recommendations. Thanks!