khatru: expiration manager takes query and delete methods, which are given automatically by .UseEventstore()

This commit is contained in:
fiatjaf
2025-10-01 12:08:08 -03:00
parent 8957144c77
commit 46f28203ed
2 changed files with 46 additions and 46 deletions

View File

@@ -6,7 +6,6 @@ import (
"log"
"net/http"
"os"
"slices"
"strconv"
"strings"
"sync"
@@ -53,8 +52,6 @@ func NewRelay() *Relay {
MaxAuthenticatedClients: 32,
}
rl.expirationManager = newExpirationManager(rl)
return rl
}
@@ -152,7 +149,7 @@ func (rl *Relay) UseEventstore(store eventstore.Store, maxQueryLimit int) {
}
// only when using the eventstore we automatically set up the expiration manager
rl.StartExpirationManager()
rl.StartExpirationManager(rl.QueryStored, rl.DeleteEvent)
}
func (rl *Relay) getBaseURL(r *http.Request) string {
@@ -180,21 +177,3 @@ func (rl *Relay) getBaseURL(r *http.Request) string {
}
return proto + "://" + host
}
func (rl *Relay) StartExpirationManager() {
if rl.expirationManager != nil {
go rl.expirationManager.start(rl.ctx)
rl.Info.AddSupportedNIP(40)
}
}
func (rl *Relay) DisableExpirationManager() {
rl.expirationManager.stop()
rl.expirationManager = nil
idx := slices.Index(rl.Info.SupportedNIPs, 40)
if idx != -1 {
rl.Info.SupportedNIPs[idx] = rl.Info.SupportedNIPs[len(rl.Info.SupportedNIPs)-1]
rl.Info.SupportedNIPs = rl.Info.SupportedNIPs[0 : len(rl.Info.SupportedNIPs)-1]
}
}