add KeepRecentEvents

This commit is contained in:
Yasuhiro Matsumoto
2024-03-24 19:18:32 +09:00
parent 7798055b1b
commit 21f4750ac3
2 changed files with 4 additions and 0 deletions

View File

@@ -12,6 +12,7 @@ type PostgresBackend struct {
QueryAuthorsLimit int
QueryKindsLimit int
QueryTagsLimit int
KeepRecentEvents bool
}
func (b *PostgresBackend) Close() {

View File

@@ -32,6 +32,9 @@ func (b *PostgresBackend) BeforeSave(ctx context.Context, evt *nostr.Event) {
}
func (b *PostgresBackend) AfterSave(evt *nostr.Event) {
if b.KeepRecentEvents {
return
}
// delete all but the 100 most recent ones for each key
b.DB.Exec(`DELETE FROM event WHERE pubkey = $1 AND kind = $2 AND created_at < (
SELECT created_at FROM event WHERE pubkey = $1