Open
Conversation
Owner
|
Are we missing the code refactor to use the new flag on the users table? |
There was a problem hiding this comment.
Pull request overview
Adds a database-level optimization for NIP-62 “request-to-vanish” checks by introducing a persisted users.is_vanished flag and backfilling it from existing kind-62 events, reducing reliance on repeated events table lookups.
Changes:
- Add
is_vanishedboolean column to theuserstable (defaultfalse, not nullable). - Backfill
is_vanished = truefor users with non-deleted kind-62 events and insert missingusersrows for pubkeys that have active kind-62 events.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+15
to
+29
| await knex.raw(` | ||
| INSERT INTO users (pubkey, is_admitted, balance, is_vanished, created_at, updated_at) | ||
| SELECT DISTINCT e.event_pubkey, false, 0, true, NOW(), NOW() | ||
| FROM events e | ||
| LEFT JOIN users u ON u.pubkey = e.event_pubkey | ||
| WHERE e.event_kind = 62 | ||
| AND e.deleted_at IS NULL | ||
| AND u.pubkey IS NULL | ||
| `) | ||
| } | ||
|
|
||
| exports.down = function (knex) { | ||
| return knex.schema.alterTable('users', (table) => { | ||
| table.dropColumn('is_vanished') | ||
| }) |
Comment on lines
+9
to
+12
| FROM events e | ||
| WHERE u.pubkey = e.event_pubkey | ||
| AND e.event_kind = 62 | ||
| AND e.deleted_at IS NULL |
Contributor
Author
|
Hey @cameri ! I made migration reversible (removed user inserts from events) and optimized backfill query using EXISTS. Also missing users issue is solved by adding lazy hydration for |
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.
This PR introduces a new
is_vanishedcolumn on theuserstable to support a more efficient way of handling NIP-62 (request-to-vanish) checks.Related Issue
Currently NIP-62 query the
eventstable for active kind-62 records on every check.Fixes issue #436
Motivation and Context
The relay have to check every pubkey for an active request-to-vanish by querying events.As events volume grows ,this becomes less efficient. So we introduced a
is_vanishedflag in users table for faster checks.How Has This Been Tested?
npm run build:checknpm run test:unit(504 passing)Types of changes
Checklist: