Skip to content

fix(users): resolve the cursor and count every membership in a user's memberships list - #14579

Merged
abnegate merged 2 commits into
mainfrom
qfix-user-memberships-cursor
Oct 16, 2026
Merged

abnegate merged 2 commits into
mainfrom
qfix-user-memberships-cursor

Conversation

@abnegate

Copy link
Copy Markdown
Member

What

Staging QA found two problems with GET /v1/users/{userId}/memberships:

  • Any cursorAfter/cursorBefore query answered 500 with "Invalid cursor: a cursor must be a document, string given".
  • total was the size of the returned page, so with limit(1) it was always 1.

Why

Users/Http/Users/Memberships/XList.php never resolved the cursor's membership ID into a document before calling find(), so the database refused the raw string. It also set total to count($memberships) instead of counting the matching rows.

Fix

The action now does what Teams/Http/Memberships/XList.php does:

  • It validates the cursor, loads the membership and sets it as the cursor value. An unknown ID answers 400 general_cursor_not_found.
  • total comes from count() over the filter queries, capped at APP_LIMIT_COUNT, and is still 0 with total=false.
  • A null order value maps to database_query_order_null.

In the same file, testListUserMemberships swaps the deprecated Query::contains on the roles array for containsAny.

Tests

The fix is in the HTTP action, so the E2E tests are the fixing-layer tests (tests/e2e/Services/Users/UsersBase.php):

Test (UsersCustomServerTest) origin/main this PR
testListUserMembershipsPaginatesWithACursor: cursorAfter + limit, cursorBefore, unknown cursor ❌ 500 general_unknown ✅ 200, then 400 general_cursor_not_found for the unknown ID
testListUserMembershipsTotalCountsEveryMembership: 3 memberships, limit(1) ❌ total 1 ✅ total 3, and 0 with total=false

Full UsersCustomServerTest (69 tests) and UsersConsoleClientTest pass locally.

🤖 Generated with Claude Code

… memberships list

GET /v1/users/{userId}/memberships passed a cursor query to the database with
the raw membership ID as its value, which the database refuses with "a cursor
must be a document", so any cursor answered 500. The action now resolves the
ID to its membership as the team memberships list does, and answers 400
general_cursor_not_found for an unknown one.

total was the number of memberships on the page, so a limit capped it; it is
now the count of every membership matching the filters.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@luxor-code-review

luxor-code-review Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


This PR upgrades the users memberships list endpoint from client-side slicing to proper server-side cursor pagination, and aligns its response metadata with the real filtered result set. The e2e suite is extended to exercise the new pagination contract end to end.

Files Change
src/Appwrite/Platform/Modules/Users/Http/Users/Memberships/XList.php Switches listing to database-level cursor pagination (cursor/cursorBefore/cursorAfter with limit) and reports total reflecting the full filtered set.
tests/e2e/Services/Users/UsersBase.php Adds e2e coverage asserting pagination links, per-page limits, and cursor navigation across membership pages.

Reviewed commit: c5a63a6

@ghost

ghost commented Oct 16, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The changed action follows the established memberships-list cursor pattern and the new tests cover the reported behavior.

The users-memberships list now resolves cursor IDs to membership documents, returns the filtered membership count up to the configured cap, and maps null-order errors to the API error. The E2E coverage exercises cursor pagination, missing cursors, total counts, and the total=false behavior; the existing roles query now uses containsAny.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 2
File Change
src/Appwrite/Platform/Modules/Users/Http/Users/Memberships/XList.php Resolve membership cursors and calculate the filtered total count.
tests/e2e/Services/Users/UsersBase.php Update the roles query and add E2E coverage for pagination and totals.

Merged main (0fe6fcd); no changes to this PR's code since c5a63a6 · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@github-actions

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

19 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (12)
  • php.appwrite.secret-compare-timing (5)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Tier S · Looks good to merge. Summary

@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → qfix-user-memberships-cursor (after).

Metric Before After Change
🚀 Requests/sec 164.04 182.58 🟢 +11.3%
⏱️ Latency P50 103.93 ms 95.31 ms 🟢 -8.3%
⏱️ Latency P95 257.5 ms 220.29 ms 🟢 -14.5%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 95.31 220.29 11,400 182.58 -37.22
Account 176.83 323.32 600 10.4 -73.06
TablesDB 91.25 176.84 6,200 103.09 -18.27
Storage 88.51 203.61 3,000 51.15 -20.82
Functions 134.99 252.32 1,600 28.15 -81.81

Top API waits (after)

API request Max wait (ms)
account.name.update 524.29
functions.create 431.49
account.prefs.update 418.59
tablesdb.rows.create 408.6
account.get 396.96

@abnegate
abnegate merged commit c036b71 into main Oct 16, 2026
34 checks passed
@ChiragAgg5k ChiragAgg5k mentioned this pull request Oct 21, 2026
6 tasks
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.

1 participant