an app.bsky.* indexer

Compare changes

Choose any two refs to compare.

Changed files
+9 -26
cmd
+1 -1
cmd/monarch/backfill.go
···
ParallelBackfills: cctx.Int("backfill-workers"),
ParallelRecordCreates: cctx.Int("backfill-consumers"),
NSIDFilter: "",
-
SyncRequestsPerSecond: 10,
RelayHost: "https://" + cctx.String("relay-host"),
}
···
ParallelBackfills: cctx.Int("backfill-workers"),
ParallelRecordCreates: cctx.Int("backfill-consumers"),
NSIDFilter: "",
+
SyncRequestsPerSecond: cctx.Int("sync-requests-limit"),
RelayHost: "https://" + cctx.String("relay-host"),
}
+4 -20
cmd/monarch/census.go
···
)
type CensusService struct {
-
cursor *CursorService
-
backfill *backfill.Backfiller
-
seenHosts map[string]bool
-
seenLk sync.Mutex
-
-
storeLk sync.Mutex
}
type jobMaker interface {
···
for _, host := range res.Hosts {
// don't reprocess hosts already handled
-
cs.seenLk.Lock()
-
_, ok := cs.seenHosts[host.Hostname]
-
cs.seenLk.Unlock()
-
if ok {
slog.Info("already processed host, skipping", "host", host)
continue
}
···
return
}
-
cs.storeLk.Lock()
hcur, err := cs.cursor.GetHostCursor(host)
if err != nil {
slog.Error("error fetching host cursor", "err", err)
}
-
cs.storeLk.Unlock()
var added int
curs := hcur.Cursor
···
continue
}
-
cs.storeLk.Lock()
for _, repo := range res.Repos {
_, err := jmstore.GetOrCreateJob(ctx, repo.Did, backfill.StateEnqueued)
if err != nil {
···
added += 1
}
}
-
cs.storeLk.Unlock()
if res.Cursor != nil && *res.Cursor != "" {
curs = *res.Cursor
-
cs.storeLk.Lock()
if err := cs.cursor.SetHostCursor(host, curs); err != nil {
slog.Error("error updating cursor for host", "err", err)
}
-
cs.storeLk.Unlock()
} else {
break
}
}
slog.Info("finished listing repos", "host", host)
-
-
cs.seenLk.Lock()
-
defer cs.seenLk.Unlock()
-
cs.seenHosts[host] = true
}
···
)
type CensusService struct {
+
cursor *CursorService
+
backfill *backfill.Backfiller
seenHosts map[string]bool
}
type jobMaker interface {
···
for _, host := range res.Hosts {
// don't reprocess hosts already handled
+
seen := cs.seenHosts[host.Hostname]
+
if seen {
slog.Info("already processed host, skipping", "host", host)
continue
}
···
return
}
hcur, err := cs.cursor.GetHostCursor(host)
if err != nil {
slog.Error("error fetching host cursor", "err", err)
}
var added int
curs := hcur.Cursor
···
continue
}
for _, repo := range res.Repos {
_, err := jmstore.GetOrCreateJob(ctx, repo.Did, backfill.StateEnqueued)
if err != nil {
···
added += 1
}
}
if res.Cursor != nil && *res.Cursor != "" {
curs = *res.Cursor
if err := cs.cursor.SetHostCursor(host, curs); err != nil {
slog.Error("error updating cursor for host", "err", err)
}
} else {
break
}
}
slog.Info("finished listing repos", "host", host)
cs.seenHosts[host] = true
}
+1 -4
cmd/monarch/cursors.go
···
import (
"context"
"log/slog"
-
"sync"
"time"
"gorm.io/gorm"
)
type CursorService struct {
-
store *gorm.DB
-
-
firehoseLk sync.Mutex
firehoseSeq int64
}
···
import (
"context"
"log/slog"
"time"
"gorm.io/gorm"
)
type CursorService struct {
+
store *gorm.DB
firehoseSeq int64
}
+3 -1
cmd/monarch/firehose.go
···
func NewFirehoseConnection(ctx context.Context, cctx *cli.Context, cursorSvc *CursorService) (*websocket.Conn, error) {
url := fmt.Sprintf("wss://%s/xrpc/com.atproto.sync.subscribeRepos", cctx.String("relay-host"))
curs, err := cursorSvc.GetFirehoseCursor()
-
if err == nil { // reversed
url += fmt.Sprintf("?cursor=%d", curs)
}
···
func NewFirehoseConnection(ctx context.Context, cctx *cli.Context, cursorSvc *CursorService) (*websocket.Conn, error) {
url := fmt.Sprintf("wss://%s/xrpc/com.atproto.sync.subscribeRepos", cctx.String("relay-host"))
curs, err := cursorSvc.GetFirehoseCursor()
+
if err != nil {
+
slog.Error("error getting firehose cursor", "err", err)
+
} else if curs > 0 {
url += fmt.Sprintf("?cursor=%d", curs)
}