Skip to content

fix(nip09): collect the ids of a deletion request in one pass - #1232

Open
Priyanshubhartistm wants to merge 1 commit into
cameri:mainfrom
Priyanshubhartistm:fix/delete-event-linear-id-collection
Open

Priyanshubhartistm wants to merge 1 commit into
cameri:mainfrom
Priyanshubhartistm:fix/delete-event-linear-id-collection

Conversation

@Priyanshubhartistm

@Priyanshubhartistm Priyanshubhartistm commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Description

DeleteEventStrategy.execute built the list of event ids to delete from the e tags of a kind-5 event with

event.tags.reduce((eventIds, tag) => (isValidETag(tag) ? [...eventIds, tag[1]] : eventIds), [] as string[])

[...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.
  • All new and existing tests passed.

Signed-off-by: Priyanshubhartistm <bhartipriyanshustm@gmail.com>
@changeset-bot

changeset-bot Bot commented Nov 22, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 63bb7b5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
nostream Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Explain Change →

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.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor

Possibly related issues

  • 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: Passed 4

Check name Status Explanation
Title check Passed 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 Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed 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.

Share

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.

Files selected for processing: 3

  • .changeset/delete-event-linear-id-collection.md
  • src/handlers/event-strategies/delete-event-strategy.ts
  • test/unit/handlers/event-strategies/delete-event-strategy.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

@greptile-apps

greptile-apps Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] This PR appears safe to merge.

Summary

Replaces repeated array copying in DeleteEventStrategy.execute with one pass through the tags.

  • Deletion requests collect target IDs in one pass.

Reviews (1) · Last reviewed commit: "fix(nip09): collect the ids of a deletio..." · Reviewed by Greptile

@coveralls

Copy link
Copy Markdown
Collaborator

Coverage Report for CI Build 45061746325

Coverage increased (+0.002%) to 79.748%

Details

  • Coverage increased (+0.002%) from the base build.
  • Patch coverage: 6 of 6 lines across 1 file are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 14649
Covered Lines: 12176
Line Coverage: 83.12%
Relevant Branches: 8020
Covered Branches: 5902
Branch Coverage: 73.59%
Branches in Coverage %: Yes
Coverage Strength: 654.12 hits per line

💛 - Coveralls

This branch has not been deployed

No deployments
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.

2 participants