fix: simplify JSONB extraction - remove redundant operators
- Replace 4 LIKE checks with 2 in build_custom_field_filter - Simplify CASE blocks in migration trigger functions - ->> operator always returns text, no need for -> + ::text fallback - Performance improvement: 50% fewer LIKE operations
This commit is contained in:
parent
014ef04853
commit
265e976d94
2 changed files with 11 additions and 47 deletions
|
|
@ -529,12 +529,11 @@ defmodule Mv.Membership.Member do
|
|||
# Builds search filter for custom field values using LIKE on JSONB
|
||||
# Note: LIKE on JSONB is not index-optimized, may be slow with many custom fields
|
||||
# This is a fallback for substring matching in custom fields (e.g., phone numbers)
|
||||
# Uses ->> operator which always returns TEXT directly (no need for -> + ::text fallback)
|
||||
defp build_custom_field_filter(pattern) do
|
||||
expr(
|
||||
fragment(
|
||||
"EXISTS (SELECT 1 FROM custom_field_values WHERE member_id = id AND (value->>'_union_value' LIKE ? OR value->>'value' LIKE ? OR (value->'_union_value')::text LIKE ? OR (value->'value')::text LIKE ?))",
|
||||
^pattern,
|
||||
^pattern,
|
||||
"EXISTS (SELECT 1 FROM custom_field_values WHERE member_id = id AND (value->>'_union_value' LIKE ? OR value->>'value' LIKE ?))",
|
||||
^pattern,
|
||||
^pattern
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue