You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(nip09): collect the ids of a deletion request in one pass - #1232
[...eventIds, tag[1]] copies everything collected so far for each tag, so the work grows with the square of the number of e tags. The default limits.message.maxPayloadSize is 512 KB, which holds about 7,000 ["e", "<64 hex>"] tags (73 bytes each), and the loop runs synchronously on the worker before any id is looked up and before the event is stored. I timed the two forms in plain Node on 7,000 valid tags: about 40 ms for the reduce with a spread, about 1 ms for one pass. Any client that can get a kind-5 event accepted can make the worker busy for that long per event, whether or not any of the referenced events exist.
the ids are collected in one pass into a Set, then passed on as an array;
an id that appears more than once is asked for once, in the order it first appears. deleteByPubkeyAndIds uses a WHERE ... IN, so which events are deleted does not change; it only stops a repeated id from being sent 7,000 times;
nothing else in the strategy changes.
Related Issue
Partly addresses #1020 (finding F-038). That issue groups six findings; this PR does F-038, so it does not close the issue.
Motivation and Context
Work done for a message should grow with its size, not with the square of it.
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Non-functional change (docs, style, minor refactor)
Bug fix (non-breaking change which fixes an issue)
New feature (non-breaking change which adds functionality)
Breaking change (fix or feature that would cause existing functionality to change)
Checklist:
My code follows the code style of this project.
My change requires a change to the documentation.
I have updated the documentation accordingly.
I have read the CONTRIBUTING document.
I have added tests to cover my code changes.
I added a changeset, or this is docs-only and I added an empty changeset.
No actionable comments were generated in the recent review.
Walkthrough
DeleteEventStrategy.execute collects valid event IDs in a Set and requests deletion with unique IDs in first-seen order. Tests cover invalid tags, empty results, and 7,000 event tags. A changeset declares a patch release.
Changes: Delete event ID collection
Layer / File(s)
Summary
Collect IDs and verify deletion src/handlers/event-strategies/delete-event-strategy.ts, test/unit/handlers/event-strategies/delete-event-strategy.spec.ts, .changeset/delete-event-linear-id-collection.md
execute collects valid IDs in a Set and calls deletion only when the set is nonempty. Tests check deduplication, first-seen order, tag validation, event creation when no valid IDs exist, and handling 7,000 tags. The changeset declares a patch release.
Issue 1020 in cameri/nostream describes quadratic array copying when kind-5 events repeat deletion tags. This change replaces that collection with a Set.
Merge Risk: Minimal · up to 63bb7
This change makes delete-event ID collection linear and requests duplicate IDs once. Deletion outcomes are unchanged, and no merge-blocking risk was found.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: DeleteEventStrategy (NIP-09) now collects the event IDs of a deletion request in a single pass. The raw summary and PR objectives confirm this, since the change replac…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check
Explanation
The title names the main change: DeleteEventStrategy (NIP-09) now collects the event IDs of a deletion request in a single pass. The raw summary and PR objectives confirm this, since the change replaces repeated array-spread collection with a single-pass Set. The conventional-commit prefix 'fix(nip09)' fits a performance and correctness change in the NIP-09 deletion handling. The title is concise, specific, and free of file lists or vague terms.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
A rabbit gathers IDs in a set No duplicate tag can sneak in yet First-seen order stays in line Bad tags leave no trace behind Seven thousand hop along Deletion gets the IDs, all strong
Recent review info
Automatic approval policy
Commit: 63bb7b5da8f3.
Setting
Effective value
Source
Automatic approvals
Enabled
Global configuration
Merge risk
Minimal
Global configuration
Security risk
Not set
Global configuration
Not set means no limit was configured after inheritance. Use @coderabbitai configuration to inspect the resolved settings and their sources.
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: d06b291d-1675-4264-b847-cbbca59c6b88
Commits
Reviewing files that changed from the base of the PR and between d5ebdff and 63bb7b5.
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.
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
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.
Description
DeleteEventStrategy.executebuilt the list of event ids to delete from theetags of a kind-5 event with[...eventIds, tag[1]]copies everything collected so far for each tag, so the work grows with the square of the number ofetags. The defaultlimits.message.maxPayloadSizeis 512 KB, which holds about 7,000["e", "<64 hex>"]tags (73 bytes each), and the loop runs synchronously on the worker before any id is looked up and before the event is stored. I timed the two forms in plain Node on 7,000 valid tags: about 40 ms for thereducewith a spread, about 1 ms for one pass. Any client that can get a kind-5 event accepted can make the worker busy for that long per event, whether or not any of the referenced events exist.Set, then passed on as an array;deleteByPubkeyAndIdsuses aWHERE ... IN, so which events are deleted does not change; it only stops a repeated id from being sent 7,000 times;Related Issue
Partly addresses #1020 (finding F-038). That issue groups six findings; this PR does F-038, so it does not close the issue.
Motivation and Context
Work done for a message should grow with its size, not with the square of it.
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Checklist: