Browse Source

make deletion more expliciti

imwald
Silberengel 1 week ago
parent
commit
b540fd860a
  1. 2
      src/Command/PrewarmCommand.php
  2. 21
      src/Service/Nip09DeletionApplier.php

2
src/Command/PrewarmCommand.php

@ -167,7 +167,7 @@ final class PrewarmCommand extends Command
try { try {
$st = $this->nip09DeletionApplier->apply($kind5); $st = $this->nip09DeletionApplier->apply($kind5);
$io->writeln(sprintf( $io->writeln(sprintf(
'Kind 5 events: <info>%d</info> (deduped). Articles removed: <info>%d</info>; magazine root/category cache entries removed: <info>%d</info> / <info>%d</info>.', 'Kind 5 events: <info>%d</info> (deduped). NIP-23 long-form in DB (30023/30024) removed: <info>%d</info>. Magazine index in cache (30040) removed: root <info>%d</info>, category <info>%d</info>.',
\count($kind5), \count($kind5),
$st['articles_removed'], $st['articles_removed'],
$st['magazine_roots'], $st['magazine_roots'],

21
src/Service/Nip09DeletionApplier.php

@ -13,7 +13,11 @@ use swentel\nostr\Key\Key;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
/** /**
* Applies NIP-09 (kind 5) deletion requests to local MySQL articles and magazine 30040 cache. * Applies NIP-09 (kind 5) deletion requests to:
* - MySQL: long-form articles ({@see KindsEnum::LONGFORM} 30023, {@see KindsEnum::LONGFORM_DRAFT} 30024)
* - Magazine cache: publication indices ({@see KindsEnum::PUBLICATION_INDEX} 30040) in {@see MagazineIndexStore}
*
* Both are handled for `e` tags (with `k` when present) and for NIP-33 `a` tags.
* *
* Relays are not authoritative; we only remove data we can validate (same pubkey as deletion request). * Relays are not authoritative; we only remove data we can validate (same pubkey as deletion request).
* For cached 30040 category indices (keyed by `d` only), we require the stored event’s author * For cached 30040 category indices (keyed by `d` only), we require the stored event’s author
@ -65,7 +69,12 @@ final class Nip09DeletionApplier
} }
$declared = $eKinds[$i] ?? null; $declared = $eKinds[$i] ?? null;
if ($declared !== null if ($declared !== null
&& !\in_array($declared, [30023, 30024, 30040, 1], true)) { && !\in_array($declared, [
KindsEnum::LONGFORM->value,
KindsEnum::LONGFORM_DRAFT->value,
KindsEnum::PUBLICATION_INDEX->value,
1, // NIP-09 may include kind 1; we do not store notes, but must not treat k as “unknown”
], true)) {
// Other kinds: we do not mirror in this app; skip. // Other kinds: we do not mirror in this app; skip.
continue; continue;
} }
@ -77,8 +86,12 @@ final class Nip09DeletionApplier
++$articlesPendingFlush; ++$articlesPendingFlush;
continue; continue;
} }
// No article row: 30040 index (or mis-tagged kind); only skip unrelated kinds. // No DB row: try kind 30040 magazine index by event id; also 30023/24 if not mirrored in DB.
if ($declared === null || \in_array($declared, [30023, 30024, 30040], true)) { if ($declared === null || \in_array($declared, [
KindsEnum::LONGFORM->value,
KindsEnum::LONGFORM_DRAFT->value,
KindsEnum::PUBLICATION_INDEX->value,
], true)) {
$mag = $this->tryRemoveMagazine30040ByEventId($eId, $deletionPubkey); $mag = $this->tryRemoveMagazine30040ByEventId($eId, $deletionPubkey);
if ($mag === 1) { if ($mag === 1) {
++$roots; ++$roots;

Loading…
Cancel
Save