Skip to content

fix(web): character search finds Forever characters by surname or full name - #1335

Draft
CDVolvik wants to merge 2 commits into
mainfrom
srdev/search-20261116
Draft

CDVolvik wants to merge 2 commits into
mainfrom
srdev/search-20261116

Conversation

@CDVolvik

Copy link
Copy Markdown
Collaborator

Part of #1270 (proposal item 1, the search fix).

What changed

Forever names are "First Surname", and every character search matched only the start of the first name. "Morningstar" or "Volvik Morningstar" could never find Volvik Morningstar.

  • New migration supabase/migrations/20261117140000_armory_full_name_search.sql redefines armory_search. A query now matches the start of the first name, the surname, or "first surname". It is trimmed and lower cased, and any run of spaces counts as one. The migration adds text_pattern_ops indexes on lower(surname) and lower(name || ' ' || surname); the first name already had one. The function is now PL/pgSQL, so each LIKE gets its pattern at plan time and can use its prefix index. These rules are unchanged: the armory_hides filter, the 2-character minimum, the refusal of %, _ and \, the order, the 100-row cap, the security-definer settings and the service-role-only grant. Same signature and same columns, so no caller changes are needed. The migration replaces one function and adds two indexes; it touches no table or row. It is safe to apply twice, and the rollback is at the bottom of the file.

  • players is left as it is, on purpose. Its rows are first-name sightings with no surname column. upsert_players_armory sends every full identity to the armory instead ("never collapse them into a first-name sighting"). So search_players has no surname to match, and it already has players_name_prefix (name_key text_pattern_ops). A full-name query reads only the armory.

  • Header and /search people search (web/src/lib/people-search.ts) now add armory characters (when EVERLOOT_ARMORY=1) to the existing players rows, in one Characters group:

    • armory rows show "First Surname", and the meta line says Level 31 Warrior · US PvP (region and ruleset)
    • one row per page link
    • exact names first
    • same PEOPLE_LIMIT of 8, same 25-row lookup cap
    • if one lookup fails, the other still answers

    The armory lookup is not cached, so an armory hide applies to the very next search.

  • The header box's couldBeName pre-filter now passes a surname of up to 24 letters or a full name. Before, a long full name never reached /search/people.

  • The /armory hub search box accepts a surname or a full name. The guild box is unchanged.

  • The PeopleSearch / PersonGroup / PersonResult types moved to web/src/lib/people-search-types.ts, and people-search.ts re-exports them. Without this, SearchBar.tsx (a type-only import) put the armory store on the import graph of web/scripts/export-bulk.ts, and kb/test/armory-isolation.test.ts correctly failed.

Must be applied by the maintainer: the migration is not applied anywhere. Until it is applied, the web change degrades safely: the old armory_search returns no rows for a surname or a full name. No error is thrown, and the first-name search behaves as it does today.

Not in this PR (later items of #1270): the on-demand Blizzard lookup when a search misses, the discovery crawl fixes, and the character sheet tabs. Until the crawl fills the armory (347 characters, none on PvP as of the issue), this fix only finds characters already stored.

How you tested it

  • SQL on PGlite (kb/test/armory-search-sql.test.ts): applies the armory migrations plus the new one (twice), then runs supabase/tests/armory_search.sql and supabase/tests/armory.sql. The tests check that:

    • "Volvik", "Morningstar", "morning", "Volvik Morningstar", " volvik MORNINGSTAR " and "volvik morn" each find the US and EU Volvik Morningstar
    • a hidden character, including a row re-inserted after its hide, is never returned
    • "Volvik Morningstar" does not match "Orla Volvikson"
    • one letter, wildcards and null return nothing, and the limit holds
    • the grants and the three indexes are in place
    • EXPLAIN shows each part using its prefix index

    Mutation check: without the new migration the test fails with us miss for Morningstar.

  • Web unit tests:

    • people-search.test.ts: the four required queries plus extra spacing find "Volvik Morningstar" with its region; a hidden character is not returned; players and armory rows merge with no duplicates and keep the limit; an armory failure leaves the players rows
    • search-bar.test.tsx: couldBeName
    • armory.test.tsx: the hub finds a character by surname and by full name
  • cd web && npx vitest run --maxWorkers=4 --testTimeout=60000: 5951 passed, 2 failed, 30 skipped (522 files). The 2 failures are the known Windows scripts/build-version.test.ts spawnSync npm ENOENT cases.

  • cd web && npm run typecheck: clean. npm run lint: 4 warnings, all in files this PR doesn't touch.

  • cd kb && npm test: 2187 passed, 1 skipped (183 files). npm run typecheck: clean.

  • next build was not run, because no route export or route config changed.

  • The title reads type(scope): plain sentence

  • Commits are signed off

  • No scraped, datamined or spoiler data; all fixtures are invented names

  • For an addon change: n/a

  • CHANGELOG.md has one line under [Unreleased] (### Fixed, Site:)

  • The area label is set

  • Docs are updated if behaviour changed (migration header and code comments)

…l name

Forever names are "First Surname", and every character search matched
only the start of the first name, so "Morningstar" or "Volvik
Morningstar" never found Volvik Morningstar.

- New migration redefines armory_search to match the start of the
  first name, the surname or "first surname" (trimmed, lower case, any
  run of spaces as one), with text_pattern_ops indexes on the surname
  and the full name. Hide rule, wildcard refusal, minimum length, order,
  cap and the service-role-only grant are unchanged.
- The header and /search people search now include armory characters
  with their region, alongside the addon's players rows, one row per
  page. The /armory hub accepts a full name.
- The /search/people answer types move to their own module, so the
  browser components and the export scripts never import the armory
  store.

Part of #1270.

Signed-off-by: CDVolvik <cjimenez@r21digital.com>
@mrglgl-reviewer

Copy link
Copy Markdown

Summary: This PR implements full-name character search in the armory by adding new database indexes and a PL/pgSQL function that matches first names, surnames, or full names. The web UI is updated to support surname/full name searches in both the header search box and /armory hub, with proper integration into the people search results. Key risks include potential performance issues from the new LIKE operations and the need for the migration to be applied before the web changes take effect.

Standards

  • warn · RUBRIC-correctness · supabase/migrations/20261117140000_armory_full_name_search.sql:35
    The PL/pgSQL function uses three LIKE operations with patterns built at runtime, which could cause performance issues if not properly indexed. While indexes are added for each search path (name, surname, full name), the query plan may still be suboptimal if the pattern matching is too complex or if there are many matches.
    Fix: Ensure that the LIKE patterns used in the function are simple enough to leverage the prefix indexes effectively, and consider adding additional performance monitoring for high-volume searches.
  • warn · RUBRIC-verification · web/src/components/ui/SearchBar.tsx:50
    The couldBeName function now accepts up to 24 letters for the first name and 24 letters for the surname, but the web UI search form allows up to 64 characters. This discrepancy could lead to confusion if a user enters a very long full name that gets rejected by the backend validation.
    Fix: Align the maximum character limit in couldBeName with the 64-character limit in the UI form to ensure consistency.
  • warn · RUBRIC-root-cause · web/src/lib/people-search.ts:50
    The people search logic now merges results from multiple sources (players, armory, guilds) but does not properly handle cases where one lookup fails and the others succeed. While it logs errors, it doesn't provide a clear indication to users that some data might be missing due to partial failures.
    Fix: Implement a more robust error handling mechanism that informs users when some search results are unavailable due to lookup failures.
  • warn · RUBRIC-complexity · web/src/lib/people-search.ts:42
    The group function now takes an array of lookups instead of a single array, which adds complexity to the logic for merging results. The code also introduces new type definitions and imports that increase the overall complexity of the module.
    Fix: Consider simplifying the result merging logic or providing clearer documentation on how the different lookup sources are combined.

Spec
No linked issue, so no spec check.

Checked
  • migrations: The migration is idempotent, safe to apply twice, and includes rollback instructions; it adds indexes and replaces a function without changing table structure
  • auth: No auth or RLS changes in this PR
  • secrets: No secrets or PII found in code changes
  • error paths: Error handling for armory lookups is properly implemented with fallbacks to existing players rows
  • scale: The change uses prefix indexes to avoid full table scans, and the limit of 100 rows prevents excessive resource usage

R21 rulebook review

@mrglgl-reviewer mrglgl-reviewer Bot added the review:changes Mrglgl Reviewer verdict label Nov 18, 2026
Signed-off-by: CDVolvik <cjimenez@r21digital.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

privacy Personal data, consent and analytics review:changes Mrglgl Reviewer verdict web everloot.app

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant