perf: batch expand operations to reduce DB queries - #7
Merged
Conversation
Maxim Manuylov (maxmanuylov)
requested review from
Sergey Zhuravlev (jbzhur),
Aleksandr Shubert (lure) and
Pavel Nikitin (morj)
and
a lite review from Copilot
September 1, 2026 13:19
Copilot started reviewing on behalf of
Maxim Manuylov (maxmanuylov)
September 1, 2026 13:20
View session
There was a problem hiding this comment.
Pull request overview
This PR updates the permission Expand execution to reduce per-entity database queries by batching entity IDs (IN-clause queries) and adds an internal per-operation goroutine concurrency limiter to avoid goroutine explosion during large expands.
Changes:
- Add functional options to
ExpandEnginefor concurrency limiting and max batch size, wiring these from service config. - Batch Expand’s relation expansion by grouping usersets and querying relationships for multiple entity IDs in a single call.
- Add/adjust tests to exercise the new batching paths and update version metadata.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/cmd/serve.go | Passes concurrency and batch-size options into the Expand engine using service config values. |
| internal/info.go | Bumps the build/version string. |
| internal/engines/utils.go | Introduces ExpandOption functional options (ExpandConcurrencyLimit, ExpandMaxBatchSize). |
| internal/engines/expand.go | Implements batching for expand operations and adds per-operation goroutine concurrency limiting. |
| internal/engines/expand_test.go | Updates tests for method-based expand operations and adds batching-focused test cases. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot started reviewing on behalf of
Maxim Manuylov (maxmanuylov)
September 1, 2026 13:38
View session
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.
Suppressed comments (1)
internal/engines/expand.go:44
- NewExpandEngine applies options without validating them. If ExpandConcurrencyLimit or ExpandMaxBatchSize are set to 0/negative, expandOperation will deadlock (channel capacity 0) and batching loops using i += engine.maxBatchSize can become infinite. Consider clamping to defaults after applying opts.
func NewExpandEngine(sr storage.SchemaReader, rr storage.DataReader, opts ...ExpandOption) *ExpandEngine {
engine := &ExpandEngine{
schemaReader: sr,
dataReader: rr,
concurrencyLimit: _defaultConcurrencyLimit,
maxBatchSize: _defaultMaxBatchSize,
}
for _, opt := range opts {
opt(engine)
}
return engine
Aleksandr Shubert (lure)
approved these changes
Sep 1, 2026
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.
No description provided.