Skip to content

Commit

Permalink
chore: avoid join in query
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasheartman committed Jun 14, 2024
1 parent ff525bb commit 3a39d55
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,14 @@ export class FeatureStrategiesReadModel implements IFeatureStrategiesReadModel {
'feature_name',
'environment',
this.db.raw(
"MAX(coalesce(jsonb_array_length(value->'values'), 0)) as max_values_count",
"MAX(coalesce(jsonb_array_length(constraint_value->'values'), 0)) as max_values_count",
),
)
.from(
this.db.raw(
'feature_strategies, jsonb_array_elements(constraints) AS constraint_value',
),
)
.joinRaw('JOIN jsonb_array_elements(constraints) as value ON true')
.groupBy('feature_name', 'environment')
.orderBy('max_values_count', 'desc')
.limit(1);
Expand Down

0 comments on commit 3a39d55

Please sign in to comment.