Skip to content

sdk(local_relay): enforce max_query_results on REQ - #1457

Open
TheAwiteb wants to merge 1 commit into
nostrdevkit:masterfrom
TheAwiteb:improve-max_query_results
Open

sdk(local_relay): enforce max_query_results on REQ#1457
TheAwiteb wants to merge 1 commit into
nostrdevkit:masterfrom
TheAwiteb:improve-max_query_results

Conversation

@TheAwiteb

Copy link
Copy Markdown
Member

Previously, max_query_results was not applied when a REQ contained multiple filters. Each filter's limit is now determined individually: use the filter's .ids count or its limit, bounded by max_filter_limit, or default_filter_limit if none is set.

If the sum of all filter limits exceeds max_query_results, the total is split among filters. For example, with max_query_results=6 and two filters each requesting 5 events, each filter gets 3. If the number is not divisible (e.g., 7), the filters may get 4, slightly exceeding the max, which is acceptable.

Notes to the reviewers

I'm not a fan of the global limit approach. I added a TODO for filters requesting specific IDs: their limit should strictly be the number of IDs provided, and the remaining max_query_results budget should then be split among the filters that don't use IDs.

Of course, we still need to respect the global cap if all filters are ID-based and their total exceeds max_query_results.

Checklist

  • I followed the contribution guidelines
  • I updated the relevant CHANGELOG.md (if applicable)
  • I understand and can explain all code in this PR

Previously, max_query_results was not applied when a REQ contained
multiple filters. Each filter's limit is now determined individually:
use the filter's `.ids` count or its limit, bounded by max_filter_limit,
or default_filter_limit if none is set.

If the sum of all filter limits exceeds max_query_results, the total
is split among filters. For example, with max_query_results=6 and two
filters each requesting 5 events, each filter gets 3. If the number is
not divisible (e.g., 7), the filters may get 4, slightly exceeding the
max, which is acceptable.

Signed-off-by: Awiteb <a@4rs.nl>
@TheAwiteb
TheAwiteb requested a review from yukibtc as a code owner August 20, 2026 09:12
@codecov

codecov Bot commented Aug 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

yukibtc added a commit that referenced this pull request Aug 22, 2026
Refactor filter limit configuration and checks. Use `max_filter_limit` as the limit for each filter. The combination of `max_filter_limit` and `max_filters_per_req` determines the maximum number of query results per request.

Deprecate `LocalRelayBuilder::max_query_results` and `LocalRelayBuilder::default_filter_limit` in favor of `LocalRelayBuilder::max_filters_per_req` and `LocalRelayBuilder::max_filter_limit`, respectively.

Replaces #1457

Pull-Request: #1461
Signed-off-by: Yuki Kishimoto <yukikishimoto@protonmail.com>
yukibtc added a commit that referenced this pull request Aug 22, 2026
Refactor filter limit configuration and checks. Use `max_filter_limit` as the limit for each filter. The combination of `max_filter_limit` and `max_filters_per_req` determines the maximum number of query results per request.

Deprecate `LocalRelayBuilder::max_query_results` and `LocalRelayBuilder::default_filter_limit` in favor of `LocalRelayBuilder::max_filters_per_req` and `LocalRelayBuilder::max_filter_limit`, respectively.

Replaces #1457

Pull-Request: #1461
Signed-off-by: Yuki Kishimoto <yukikishimoto@protonmail.com>
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