Safely close databases

This commit is contained in:
Yasuhiro Matsumoto
2023-12-25 00:07:17 +09:00
committed by fiatjaf_
parent 5e40dc96ba
commit ba7261eee8
2 changed files with 22 additions and 9 deletions

View File

@@ -17,11 +17,10 @@ func updateArchives(ctx context.Context) {
select {
case <-ctx.Done():
return
default:
case <-time.After(24 * time.Hour):
loadNpubsArchive(ctx)
loadRelaysArchive(ctx)
}
time.Sleep(24 * time.Hour)
}
}
@@ -29,7 +28,11 @@ func deleteOldCachedEvents(ctx context.Context) {
wdb := eventstore.RelayWrapper{Store: db}
for {
time.Sleep(time.Hour)
select {
case <-ctx.Done():
return
case <-time.After(time.Hour):
}
log.Debug().Msg("deleting old cached events")
now := time.Now().Unix()
for _, key := range cache.GetPaginatedKeys("ttl:", 1, 500) {