Skip to content

Treat kind 0 (profiles) as replaceable per NIP-01#72

Merged
alejandro-runner merged 1 commit intomainfrom
fix/68-kind-0-replaceable-lambda
Feb 3, 2026
Merged

Treat kind 0 (profiles) as replaceable per NIP-01#72
alejandro-runner merged 1 commit intomainfrom
fix/68-kind-0-replaceable-lambda

Conversation

@alejandro-runner
Copy link
Member

Summary

Nostr kind 0 (metadata) is replaceable: only the latest event per pubkey should be kept. The Lambda previously deduplicated kind 0 by event id, so every profile update was stored and search_food_establishments returned duplicate entries (e.g. multiple "El Candado" with the same @id).

Changes

  • In-memory dedup: Kind 0 is now deduplicated by pubkey using key 0:${event.pubkey}; the event with the latest created_at is kept.
  • findExistingKind0Event(pubkey): New helper that scans DynamoDB for kind 0 with the given pubkey and returns the event with the maximum created_at (or null).
  • shouldStoreEvent: New branch for event.kind === 0: if an existing kind 0 exists, store only if the new event is newer and return oldEventId so the store loop can delete the previous row.
  • buildEventMap: Dedup logic extracted to dedup.ts and used in queryNostrRelays; unit tests added in dedup.test.ts.

Lambda tests: cd lambda/nostr-querier && npm test (3 tests for kind 0 and general dedup).

Closes #68

- Deduplicate kind 0 in-memory by pubkey, keep latest by created_at
- Add findExistingKind0Event() to look up current profile in DynamoDB
- In shouldStoreEvent, replace existing kind 0 when newer event arrives
- Extract buildEventMap to dedup.ts for testability; add unit tests

Closes #68

Co-authored-by: Cursor <cursoragent@cursor.com>
@vercel
Copy link

vercel bot commented Feb 3, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
mcp-server Ready Ready Preview, Comment Feb 3, 2026 9:58pm

@alejandro-runner alejandro-runner merged commit 95db157 into main Feb 3, 2026
5 checks passed
@alejandro-runner alejandro-runner deleted the fix/68-kind-0-replaceable-lambda branch February 3, 2026 22:03
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.

Lambda: Treat kind 0 (profiles) as replaceable per NIP-01

1 participant