From 7efadf5e0bfc307e83ffe23836ae3eb88cd3d92f Mon Sep 17 00:00:00 2001 From: dependentmadani Date: Tue, 22 Oct 2024 13:46:37 +0100 Subject: [PATCH] update (note parents): add comment about the query --- .../storage/postgres/orm/sequelize/noteRelations.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/repository/storage/postgres/orm/sequelize/noteRelations.ts b/src/repository/storage/postgres/orm/sequelize/noteRelations.ts index f7f24b34..e7eb9aa8 100644 --- a/src/repository/storage/postgres/orm/sequelize/noteRelations.ts +++ b/src/repository/storage/postgres/orm/sequelize/noteRelations.ts @@ -217,7 +217,10 @@ export default class NoteRelationsSequelizeStorage { * @param noteId - the ID of the note. */ public async getNoteParentsIds(noteId: NoteInternalId): Promise { - // get all note ids via a singe sql query instead of many + // Query to get all parent notes of a note. + // The query uses a recursive common table expression (CTE) to get all parent notes of a note. + // It starts from the note with the ID :startNoteId and recursively gets all parent notes. + // It returns a list of note ID and parent ID of the note. const query = ` WITH RECURSIVE note_parents AS ( SELECT np.note_id, np.parent_id