Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make BGS spidering optional #396

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion cmd/bigsky/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ func run(args []string) {
Name: "aggregation",
Value: false,
},
&cli.BoolFlag{
Name: "spidering",
Value: true,
EnvVars: []string{"BGS_SPIDERING"},
},
&cli.StringFlag{
Name: "api-listen",
Value: ":2470",
Expand Down Expand Up @@ -278,7 +283,7 @@ func Bigsky(cctx *cli.Context) error {

notifman := &notifs.NullNotifs{}

ix, err := indexer.NewIndexer(db, notifman, evtman, cachedidr, repoman, true, cctx.Bool("aggregation"))
ix, err := indexer.NewIndexer(db, notifman, evtman, cachedidr, repoman, true, cctx.Bool("spidering"), cctx.Bool("aggregation"))
if err != nil {
return err
}
Expand Down
11 changes: 7 additions & 4 deletions indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,14 @@ type Indexer struct {
LimitMux sync.RWMutex

doAggregations bool
doSpider bool

SendRemoteFollow func(context.Context, string, uint) error
CreateExternalUser func(context.Context, string) (*models.ActorInfo, error)
ApplyPDSClientSettings func(*xrpc.Client)
}

func NewIndexer(db *gorm.DB, notifman notifs.NotificationManager, evtman *events.EventManager, didr did.Resolver, repoman *repomgr.RepoManager, crawl, aggregate bool) (*Indexer, error) {
func NewIndexer(db *gorm.DB, notifman notifs.NotificationManager, evtman *events.EventManager, didr did.Resolver, repoman *repomgr.RepoManager, crawl, aggregate, spider bool) (*Indexer, error) {
db.AutoMigrate(&models.FeedPost{})
db.AutoMigrate(&models.ActorInfo{})
db.AutoMigrate(&models.FollowRecord{})
Expand All @@ -72,6 +73,7 @@ func NewIndexer(db *gorm.DB, notifman notifs.NotificationManager, evtman *events
didr: didr,
Limiters: make(map[uint]*rate.Limiter),
doAggregations: aggregate,
doSpider: spider,
SendRemoteFollow: func(context.Context, string, uint) error {
return nil
},
Expand Down Expand Up @@ -181,10 +183,11 @@ func (ix *Indexer) handleRepoOp(ctx context.Context, evt *repomgr.RepoEvent, op
return fmt.Errorf("handle recordCreate: %w", err)
}
}
if err := ix.crawlRecordReferences(ctx, op); err != nil {
return err
if ix.doSpider {
if err := ix.crawlRecordReferences(ctx, op); err != nil {
return err
}
}

case repomgr.EvtKindDeleteRecord:
if ix.doAggregations {
if err := ix.handleRecordDelete(ctx, evt, op, true); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion indexer/posts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func testIndexer(t *testing.T) *testIx {

didr := testPLC(t)

ix, err := NewIndexer(maindb, notifman, evtman, didr, repoman, false, true)
ix, err := NewIndexer(maindb, notifman, evtman, didr, repoman, false, true, true)
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion pds/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func NewServer(db *gorm.DB, cs *carstore.CarStore, serkey *did.PrivKey, handleSu
repoman := repomgr.NewRepoManager(cs, kmgr)
notifman := notifs.NewNotificationManager(db, repoman.GetRecord)

ix, err := indexer.NewIndexer(db, notifman, evtman, didr, repoman, false, true)
ix, err := indexer.NewIndexer(db, notifman, evtman, didr, repoman, false, true, true)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion testing/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ func SetupBGS(ctx context.Context, didr plc.PLCClient) (*TestBGS, error) {

evtman := events.NewEventManager(diskpersist)

ix, err := indexer.NewIndexer(maindb, notifman, evtman, didr, repoman, true, true)
ix, err := indexer.NewIndexer(maindb, notifman, evtman, didr, repoman, true, true, true)
if err != nil {
return nil, err
}
Expand Down
Loading