Skip to content

Commit

Permalink
chore: optimize sql query to not concatenate (#5321)
Browse files Browse the repository at this point in the history
  • Loading branch information
sjaanus authored Nov 13, 2023
1 parent 7f4df19 commit 00327c3
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/lib/features/feature-toggle/feature-toggle-strategies-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,13 +562,21 @@ class FeatureStrategiesStore implements IFeatureStrategiesStore {
]);
}
if (hasHalfTag) {
const tagParameter = normalizedHalfTag.map((tag) => `%${tag}%`);
tagQuery.orWhereRaw(
`(?? || ':' || ??) ILIKE ANY (ARRAY[${tagParameter
.map(() => '?')
.join(',')}])`,
['tag_type', 'tag_value', ...tagParameter],
const tagParameters = normalizedHalfTag.map(
(tag) => `%${tag}%`,
);
const tagQueryParameters = normalizedHalfTag
.map(() => '?')
.join(',');
tagQuery
.orWhereRaw(
`(??) ILIKE ANY (ARRAY[${tagQueryParameters}])`,
['tag_type', ...tagParameters],
)
.orWhereRaw(
`(??) ILIKE ANY (ARRAY[${tagQueryParameters}])`,
['tag_value', ...tagParameters],
);
}

query = query.where((builder) => {
Expand Down

0 comments on commit 00327c3

Please sign in to comment.