Repository navigation
feat(user): read many users in one call - #152
Merged
Merged
Conversation
If you list an org's members today, you have to call GetUser once per member. GetUsers reads them all in one query on postgres, sqlite and mongo, and in one pass under the lock on memory. It sits on its own user.BatchGetter interface so stores outside this repo keep compiling. Type-assert for it and fall back to GetUser when it isn't there. Deleted and unknown IDs are left out, and a duplicate ID comes back once. The new GetUsersBatch conformance case checks that on every backend.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
user.BatchGetter, an optional interface with one method,GetUsers(ctx, userIDs), and implements it on all four built-in stores.You get back the live users among the IDs you pass, in no particular order. Deleted and unknown IDs are simply left out, duplicates are read once, and an empty list returns straight away without a query.
Hallproof needs this. It lists an organisation's members and then wants each member's name and email, which with only
GetUsermeans one query per member. WithGetUsersit's one query for the whole organisation.It's a separate interface, not a new method on
user.Store, so a store you've written yourself keeps compiling. Callers type-assert for it and fall back toGetUserwhen a store doesn't have it.Testing
GetUsersBatchcase instoretest.RunConformancecreates three users, deletes one, then looks up live, deleted, unknown and duplicate IDs. It also covers nil and empty input.go test, and on postgres and mongo with-tags integration(the testcontainers Postgres, and a throwaway mongo:7 replica set).go test ./...,go vet ./...andgolangci-lintare clean. We didn't run the fullmake test-integrationacross every plugin package.Postgres and SQLite bind each ID as its own parameter, so one call is capped by the driver's parameter limit (65,535 on Postgres). That's far beyond any organisation's member count, but worth knowing if you pass it a huge list.