-
Notifications
You must be signed in to change notification settings - Fork 24
/
routines.go
62 lines (55 loc) · 1.52 KB
/
routines.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"context"
"time"
"github.com/nbd-wtf/go-nostr"
)
var npubsArchive = make([]string, 0, 5000)
func updateArchives(ctx context.Context) {
for {
select {
case <-ctx.Done():
return
case <-time.After(24 * time.Hour * 3):
log.Debug().Msg("refreshing the npubs archive")
for _, pubkey := range s.TrustedPubKeys {
ctx, cancel := context.WithTimeout(ctx, time.Second*4)
follows := sys.FetchFollowList(ctx, pubkey)
fla := &FollowListArchive{
Source: pubkey,
Pubkeys: make([]string, 0, 2000),
}
for _, follow := range follows.Items {
fla.Pubkeys = append(fla.Pubkeys, follow.Pubkey)
}
cancel()
if err := internal.overwriteFollowListArchive(fla); err != nil {
log.Fatal().Err(err).Msg("failed to overwrite archived pubkeys")
}
}
}
}
}
func deleteOldCachedEvents(ctx context.Context) {
for {
select {
case <-ctx.Done():
return
case <-time.After(time.Hour * 6):
log.Debug().Msg("deleting old cached events")
if ids, err := internal.deleteExpiredEvents(nostr.Now()); err != nil {
log.Fatal().Err(err).Msg("failed to delete expired events")
} else {
if ch, err := sys.Store.QueryEvents(ctx, nostr.Filter{IDs: ids}); err != nil {
log.Fatal().Err(err).Strs("ids", ids).Msg("fail to delete cached events")
} else {
for evt := range ch {
if err := sys.Store.DeleteEvent(ctx, evt); err != nil {
log.Error().Err(err).Stringer("event", evt).Msg("failed to delete this cached event")
}
}
}
}
}
}
}