perf: remove custom field search from user-linking autocomplete
Custom field LIKE queries on JSONB are expensive (no index). User linking only needs name/email search for autocomplete. Custom fields are still searchable via main member search (uses FTS index). Remove unnecessary credo:disable as function complexity is now acceptable.
This commit is contained in:
parent
062dad99fb
commit
1ec6188884
1 changed files with 4 additions and 8 deletions
|
|
@ -579,9 +579,9 @@ defmodule Mv.Membership.Member do
|
||||||
# - Empty user_email ("") → email == "" is always false → only fuzzy search matches
|
# - Empty user_email ("") → email == "" is always false → only fuzzy search matches
|
||||||
# - This allows a single filter expression instead of duplicating fuzzy search logic
|
# - This allows a single filter expression instead of duplicating fuzzy search logic
|
||||||
#
|
#
|
||||||
# Cyclomatic complexity is unavoidable here: PostgreSQL fuzzy search requires
|
# Note: Custom field search is intentionally excluded from linking to optimize
|
||||||
# multiple OR conditions for good search quality (FTS + trigram similarity + substring)
|
# autocomplete performance. Custom fields are still searchable via the main
|
||||||
# credo:disable-for-next-line Credo.Check.Refactor.CyclomaticComplexity
|
# member search which uses the indexed search_vector.
|
||||||
defp apply_linking_filters(query, user_email, search_query) do
|
defp apply_linking_filters(query, user_email, search_query) do
|
||||||
has_search = search_query && String.trim(search_query) != ""
|
has_search = search_query && String.trim(search_query) != ""
|
||||||
# Use empty string instead of nil to simplify filter logic
|
# Use empty string instead of nil to simplify filter logic
|
||||||
|
|
@ -591,11 +591,8 @@ defmodule Mv.Membership.Member do
|
||||||
# Search query provided: return email-match OR fuzzy-search candidates
|
# Search query provided: return email-match OR fuzzy-search candidates
|
||||||
trimmed_search = String.trim(search_query)
|
trimmed_search = String.trim(search_query)
|
||||||
|
|
||||||
pat = "%" <> trimmed_search <> "%"
|
# Build search filters - excluding custom_field_filter for performance
|
||||||
|
|
||||||
# Build search filters using modular functions for maintainability
|
|
||||||
fts_match = build_fts_filter(trimmed_search)
|
fts_match = build_fts_filter(trimmed_search)
|
||||||
custom_field_match = build_custom_field_filter(pat)
|
|
||||||
fuzzy_match = build_fuzzy_filter(trimmed_search, @default_similarity_threshold)
|
fuzzy_match = build_fuzzy_filter(trimmed_search, @default_similarity_threshold)
|
||||||
email_substring_match = expr(contains(email, ^trimmed_search))
|
email_substring_match = expr(contains(email, ^trimmed_search))
|
||||||
|
|
||||||
|
|
@ -606,7 +603,6 @@ defmodule Mv.Membership.Member do
|
||||||
# If email is "", this is always false and search filters take over
|
# If email is "", this is always false and search filters take over
|
||||||
email == ^trimmed_email or
|
email == ^trimmed_email or
|
||||||
^fts_match or
|
^fts_match or
|
||||||
^custom_field_match or
|
|
||||||
^fuzzy_match or
|
^fuzzy_match or
|
||||||
^email_substring_match
|
^email_substring_match
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue