From 1ec618888419f2e34127b504344c9d7b67a14faa Mon Sep 17 00:00:00 2001 From: Moritz Date: Thu, 11 Dec 2025 13:43:13 +0100 Subject: [PATCH] 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. --- lib/membership/member.ex | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/membership/member.ex b/lib/membership/member.ex index 37f8535..100f4aa 100644 --- a/lib/membership/member.ex +++ b/lib/membership/member.ex @@ -579,9 +579,9 @@ defmodule Mv.Membership.Member do # - Empty user_email ("") → email == "" is always false → only fuzzy search matches # - This allows a single filter expression instead of duplicating fuzzy search logic # - # Cyclomatic complexity is unavoidable here: PostgreSQL fuzzy search requires - # multiple OR conditions for good search quality (FTS + trigram similarity + substring) - # credo:disable-for-next-line Credo.Check.Refactor.CyclomaticComplexity + # Note: Custom field search is intentionally excluded from linking to optimize + # autocomplete performance. Custom fields are still searchable via the main + # member search which uses the indexed search_vector. defp apply_linking_filters(query, user_email, search_query) do has_search = search_query && String.trim(search_query) != "" # 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 trimmed_search = String.trim(search_query) - pat = "%" <> trimmed_search <> "%" - - # Build search filters using modular functions for maintainability + # Build search filters - excluding custom_field_filter for performance 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) 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 email == ^trimmed_email or ^fts_match or - ^custom_field_match or ^fuzzy_match or ^email_substring_match )