1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

feat: optimize search (#7387)

I am moving the strategies join to later part of query, because it is
not used for filtering, only need it for data.
This commit is contained in:
Jaanus Sellin 2024-06-13 13:46:06 +03:00 committed by GitHub
parent 1c2aa128be
commit 906940948b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -164,12 +164,6 @@ class FeatureSearchStore implements IFeatureSearchStore {
selectColumns = [
...selectColumns,
this.db.raw(
'has_strategies.feature_name IS NOT NULL AS has_strategies',
),
this.db.raw(
'enabled_strategies.feature_name IS NOT NULL AS has_enabled_strategies',
),
this.db.raw(`CASE
WHEN dependent_features.parent = features.name THEN 'parent'
WHEN dependent_features.child = features.name THEN 'child'
@ -248,8 +242,6 @@ class FeatureSearchStore implements IFeatureSearchStore {
'features.created_by_user_id',
);
this.applyStrategiesByEnvironment(query);
query.leftJoin('last_seen_at_metrics', function () {
this.on(
'last_seen_at_metrics.environment',
@ -329,6 +321,8 @@ class FeatureSearchStore implements IFeatureSearchStore {
.joinRaw('CROSS JOIN total_features')
.whereBetween('final_rank', [offset + 1, offset + limit])
.orderBy('final_rank');
this.applyStrategiesByEnvironment(finalQuery);
if (featureLifecycleEnabled) {
finalQuery.leftJoin(
'lifecycle',
@ -357,6 +351,14 @@ class FeatureSearchStore implements IFeatureSearchStore {
}
private applyStrategiesByEnvironment(queryBuilder: Knex.QueryBuilder) {
queryBuilder.select(
this.db.raw(
'has_strategies.feature_name IS NOT NULL AS has_strategies',
),
this.db.raw(
'enabled_strategies.feature_name IS NOT NULL AS has_enabled_strategies',
),
);
queryBuilder
.leftJoin(
this.db
@ -370,11 +372,11 @@ class FeatureSearchStore implements IFeatureSearchStore {
this.on(
'enabled_strategies.feature_name',
'=',
'features.name',
'ranked_features.feature_name',
).andOn(
'enabled_strategies.environment',
'=',
'feature_environments.environment',
'ranked_features.environment',
);
},
)
@ -388,11 +390,11 @@ class FeatureSearchStore implements IFeatureSearchStore {
this.on(
'has_strategies.feature_name',
'=',
'features.name',
'ranked_features.feature_name',
).andOn(
'has_strategies.environment',
'=',
'feature_environments.environment',
'ranked_features.environment',
);
},
);