mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-25 00:07:47 +01:00
fix: fix unstable search (#7391)
Reverting https://github.com/Unleash/unleash/pull/7387 https://github.com/Unleash/unleash/pull/7385
This commit is contained in:
parent
09d9676d66
commit
1191f162e5
@ -86,10 +86,7 @@ class FeatureSearchStore implements IFeatureSearchStore {
|
||||
.distinctOn('stage_feature')
|
||||
.orderBy([
|
||||
'stage_feature',
|
||||
{
|
||||
column: 'entered_stage_at',
|
||||
order: 'desc',
|
||||
},
|
||||
{ column: 'entered_stage_at', order: 'desc' },
|
||||
]);
|
||||
}
|
||||
|
||||
@ -164,6 +161,12 @@ class FeatureSearchStore implements IFeatureSearchStore {
|
||||
|
||||
selectColumns = [
|
||||
...selectColumns,
|
||||
this.db.raw(
|
||||
'EXISTS (SELECT 1 FROM feature_strategies WHERE feature_strategies.feature_name = features.name AND feature_strategies.environment = feature_environments.environment) as has_strategies',
|
||||
),
|
||||
this.db.raw(
|
||||
'EXISTS (SELECT 1 FROM feature_strategies WHERE feature_strategies.feature_name = features.name AND feature_strategies.environment = feature_environments.environment AND (feature_strategies.disabled IS NULL OR feature_strategies.disabled = false)) as has_enabled_strategies',
|
||||
),
|
||||
this.db.raw(`CASE
|
||||
WHEN dependent_features.parent = features.name THEN 'parent'
|
||||
WHEN dependent_features.child = features.name THEN 'child'
|
||||
@ -321,8 +324,6 @@ 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',
|
||||
@ -350,56 +351,6 @@ 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
|
||||
.select('feature_name', 'environment')
|
||||
.from('feature_strategies')
|
||||
.where(function () {
|
||||
this.whereNull('disabled').orWhere('disabled', false);
|
||||
})
|
||||
.as('enabled_strategies'),
|
||||
function () {
|
||||
this.on(
|
||||
'enabled_strategies.feature_name',
|
||||
'=',
|
||||
'ranked_features.feature_name',
|
||||
).andOn(
|
||||
'enabled_strategies.environment',
|
||||
'=',
|
||||
'ranked_features.environment',
|
||||
);
|
||||
},
|
||||
)
|
||||
.leftJoin(
|
||||
this.db
|
||||
.select('feature_name', 'environment')
|
||||
.from('feature_strategies')
|
||||
.groupBy('feature_name', 'environment')
|
||||
.as('has_strategies'),
|
||||
function () {
|
||||
this.on(
|
||||
'has_strategies.feature_name',
|
||||
'=',
|
||||
'ranked_features.feature_name',
|
||||
).andOn(
|
||||
'has_strategies.environment',
|
||||
'=',
|
||||
'ranked_features.environment',
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
private buildRankingSql(
|
||||
favoritesFirst: undefined | boolean,
|
||||
sortBy: string,
|
||||
|
@ -776,23 +776,6 @@ test('should return segments in payload with no duplicates/nulls', async () => {
|
||||
{
|
||||
name: 'my_feature_a',
|
||||
segments: [mySegment.name],
|
||||
environments: [
|
||||
{
|
||||
name: 'default',
|
||||
hasStrategies: true,
|
||||
hasEnabledStrategies: true,
|
||||
},
|
||||
{
|
||||
name: 'development',
|
||||
hasStrategies: true,
|
||||
hasEnabledStrategies: true,
|
||||
},
|
||||
{
|
||||
name: 'production',
|
||||
hasStrategies: false,
|
||||
hasEnabledStrategies: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user