Merge pull request #15 from mattn/keep-recent-events
Some checks failed
build cli / make-release (push) Has been cancelled
build cli / build-linux (push) Has been cancelled

add KeepRecentEvents
This commit is contained in:
mattn
2024-03-24 19:20:05 +09:00
committed by GitHub
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