From 084fcc6c9b6a94096ff2ca3ab61a9fc28352c11b Mon Sep 17 00:00:00 2001 From: Sergei Samokhvalov Date: Fri, 29 Nov 2024 18:13:09 +0300 Subject: [PATCH] Add extra filter by scope for optimize performance for get relations (#213) --- src/services/entry/actions/get-related-entries.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/services/entry/actions/get-related-entries.ts b/src/services/entry/actions/get-related-entries.ts index 1e421c1c..e7225b48 100644 --- a/src/services/entry/actions/get-related-entries.ts +++ b/src/services/entry/actions/get-related-entries.ts @@ -68,8 +68,15 @@ export async function getRelatedEntries( endToStart ? 'l.fromId' : 'l.toId', ) .join('entries', 'entries.entryId', endToStart ? 'l.toId' : 'l.fromId') - .where('isDeleted', false) - .where('depth', '<', 5); + .where((builder) => { + builder.where({isDeleted: false}); + + builder.andWhere('depth', '<', 5); + + if (scope) { + builder.andWhere('entries.scope', scope); + } + }); }); }) .select()