Skip to content

Commit

Permalink
Merge pull request #15 from mattn/keep-recent-events
Browse files Browse the repository at this point in the history
add KeepRecentEvents
  • Loading branch information
mattn authored Mar 24, 2024
2 parents 7798055 + 21f4750 commit b5ff298
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions postgresql/postgresql.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type PostgresBackend struct {
QueryAuthorsLimit int
QueryKindsLimit int
QueryTagsLimit int
KeepRecentEvents bool
}

func (b *PostgresBackend) Close() {
Expand Down
3 changes: 3 additions & 0 deletions postgresql/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b5ff298

Please sign in to comment.