Skip to content

Add membership ID support to player search - #116

Merged
owens1127 merged 3 commits into
mainfrom
copilot/add-search-by-membership-id
Feb 22, 2026
Merged

Add membership ID support to player search#116
owens1127 merged 3 commits into
mainfrom
copilot/add-search-by-membership-id

Conversation

Copilot AI commented Feb 22, 2026

Copy link
Copy Markdown
Contributor

The player search endpoint only supported name-based lookup. This rolls the membership ID lookup logic (already present in the /player/{membershipId}/basic endpoint) into the search backend.

Changes

  • searchForPlayer: When the query is purely numeric, runs a direct getPlayer(membershipId) lookup in parallel with the existing LIKE search via Promise.all. The membership ID result is prepended to the results if not already present (deduped by membershipId). Errors from the ID lookup are caught so they can't degrade name-based results.
  • search.test.ts: Added a test case for membership ID queries asserting the correct player is returned as the first result.
GET /player/search?query=4611686018467831285
→ returns player with matching membershipId (plus any name-based matches)

Existing name-based search behavior is fully preserved.

Original prompt

This section details on the original issue you should resolve

<issue_title>Search by Membership ID</issue_title>
<issue_description>While the player basic endpoint already does this, it would be nice to roll over this logic into the backend</issue_description>

<agent_instructions>Can we make an additive change here? IE, keep the current API, but add this support</agent_instructions>

Comments on the Issue (you are @copilot in this section)


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Co-authored-by: owens1127 <98496129+owens1127@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for searching by membership ID in backend Add membership ID support to player search Feb 22, 2026
Copilot AI requested a review from owens1127 February 22, 2026 03:14
@barecheck

barecheck Bot commented Feb 22, 2026

Copy link
Copy Markdown

Barecheck - Code coverage report

Total: 92.92%

Your code coverage diff: 0.02% ▴

✅ All code changes are covered

@owens1127
owens1127 marked this pull request as ready for review February 22, 2026 03:30
Copilot AI review requested due to automatic review settings February 22, 2026 03:30
@owens1127
owens1127 merged commit 0841355 into main Feb 22, 2026
7 checks passed
@owens1127
owens1127 deleted the copilot/add-search-by-membership-id branch February 22, 2026 03:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances the player search endpoint to support membership ID lookups in addition to the existing name-based search functionality. When a purely numeric query is detected, the system now performs a direct membership ID lookup in parallel with the name-based search, merging the results with the membership ID match appearing first.

Changes:

  • Added parallel membership ID lookup when query is purely numeric, using existing getPlayer function
  • Implemented deduplication logic to prevent duplicate results when membership ID matches appear in both searches
  • Added test case validating membership ID search returns correct player as first result

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/services/search/player-search.ts Implements parallel membership ID and name-based search with deduplication logic
src/routes/player/search.test.ts Adds test case for membership ID query functionality

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

let results = nameResults
if (membershipIdResult) {
const membershipIdBigInt = BigInt(trimmedQuery)
if (!results.some(r => r.membershipId === membershipIdBigInt)) {

Copilot AI Feb 22, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The membership ID lookup does not respect the opts.membershipType filter. When a user specifies a membershipType filter (e.g., membershipType=2 for PlayStation), the name-based search correctly filters by platform, but the direct membership ID lookup via getPlayer() does not apply this filter. This could result in returning a player from a different platform than requested.

Consider filtering the membershipIdResult by membershipType before prepending it to results, similar to how the test "full bungie name wrong platform" expects zero results when the platform doesn't match.

Suggested change
if (!results.some(r => r.membershipId === membershipIdBigInt)) {
const membershipTypeMatches =
!opts.membershipType || membershipIdResult.membershipType === opts.membershipType
if (membershipTypeMatches && !results.some(r => r.membershipId === membershipIdBigInt)) {

Copilot uses AI. Check for mistakes.
expect(data.parsed.results.length).toBeGreaterThan(0)
expect(data.parsed.results[0].membershipId).toBe(BigInt("4611686018467831285"))
}
})

Copilot AI Feb 22, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test for membership ID queries should include a test case that validates the membershipType filter is respected. Currently, there's no test verifying that when a membershipType filter is provided with a membership ID query, only players from that platform are returned (or the result is filtered out if the platform doesn't match).

Consider adding a test similar to "full bungie name wrong platform" that queries by membership ID with a mismatched membershipType to ensure proper filtering.

Suggested change
})
})
test("membership id wrong platform", async () => {
const data = await t({
query: "4611686018467831285",
membershipType: 2
})
if (data.type === "ok") {
expect(data.parsed.results).toHaveLength(0)
}
})

Copilot uses AI. Check for mistakes.
results = [membershipIdResult, ...results]
}
}

Copilot AI Feb 22, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When a membership ID result is prepended to the name-based results, the total results array can exceed the requested opts.count limit. For example, if opts.count is 10 and the name search returns 10 results, prepending the membership ID result would yield 11 results total.

Consider either slicing the results array to maintain the count limit, or documenting that membership ID matches can cause the result count to be count+1.

Suggested change
if (results.length > opts.count) {
results = results.slice(0, opts.count)
}

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Search by Membership ID

3 participants