this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

misc improvements for bgs operation (#204)

A number of logging improvements, some cli tooling changes

authored by

Whyrusleeping and committed by
GitHub
7ec50856 2ff44d97

+54 -6
+11 -3
bgs/bgs.go
··· 214 214 })) 215 215 216 216 e.HTTPErrorHandler = func(err error, ctx echo.Context) { 217 - log.Warnf("HANDLER ERROR: (%s) %s", ctx.Path(), err) 218 217 switch err := err.(type) { 219 218 case *echo.HTTPError: 220 219 if err2 := ctx.JSON(err.Code, map[string]any{ ··· 223 222 log.Errorf("Failed to write http error: %s", err2) 224 223 } 225 224 default: 226 - ctx.Response().WriteHeader(500) 225 + sendHeader := true 226 + if ctx.Path() == "/xrpc/com.atproto.sync.subscribeRepos" { 227 + sendHeader = false 228 + } 229 + 230 + log.Warnf("HANDLER ERROR: (%s) %s", ctx.Path(), err) 231 + 232 + if sendHeader { 233 + ctx.Response().WriteHeader(500) 234 + } 227 235 } 228 236 } 229 237 ··· 517 525 switch { 518 526 case env.RepoCommit != nil: 519 527 evt := env.RepoCommit 520 - log.Infof("bgs got repo append event %d from %q: %s", evt.Seq, host.Host, evt.Repo) 528 + log.Infow("bgs got repo append event", "seq", evt.Seq, "host", host.Host, "repo", evt.Repo) 521 529 u, err := bgs.lookupUserByDid(ctx, evt.Repo) 522 530 if err != nil { 523 531 if !errors.Is(err, gorm.ErrRecordNotFound) {
+13 -2
cmd/gosky/debug.go
··· 654 654 655 655 printPosts := func(posts []*bsky.FeedDefs_PostView) { 656 656 for _, p := range posts { 657 - text := p.Record.Val.(*bsky.FeedPost).Text 657 + fp, ok := p.Record.Val.(*bsky.FeedPost) 658 + if !ok { 659 + fmt.Printf("ERROR: Post had invalid record type: %T\n", p.Record.Val) 660 + continue 661 + } 662 + text := fp.Text 658 663 text = strings.Replace(text, "\n", " ", -1) 659 664 if len(text) > 70 { 660 665 text = text[:70] + "..." 661 666 } 662 - fmt.Printf("%s: %s\n", *p.Author.DisplayName, text) 667 + 668 + dn := p.Author.Handle 669 + if p.Author.DisplayName != nil { 670 + dn = *p.Author.DisplayName 671 + } 672 + 673 + fmt.Printf("%s: %s\n", dn, text) 663 674 } 664 675 } 665 676
+30 -1
cmd/gosky/main.go
··· 26 26 "github.com/bluesky-social/indigo/util" 27 27 "github.com/bluesky-social/indigo/version" 28 28 "github.com/bluesky-social/indigo/xrpc" 29 + lru "github.com/hashicorp/golang-lru" 29 30 30 31 "github.com/gorilla/websocket" 31 32 "github.com/ipfs/go-cid" ··· 925 926 }, 926 927 } 927 928 929 + type cachedHandle struct { 930 + Handle string 931 + Valid time.Time 932 + } 933 + 928 934 var readRepoStreamCmd = &cli.Command{ 929 935 Name: "readStream", 930 936 Flags: []cli.Flag{ ··· 975 981 hr := &api.ProdHandleResolver{} 976 982 resolveHandles := cctx.Bool("resolve-handles") 977 983 984 + cache, _ := lru.New(10000) 985 + resolveDid := func(ctx context.Context, did string) (string, error) { 986 + val, ok := cache.Get(did) 987 + if ok { 988 + ch := val.(*cachedHandle) 989 + if time.Now().Before(ch.Valid) { 990 + return ch.Handle, nil 991 + } 992 + } 993 + 994 + h, _, err := api.ResolveDidToHandle(ctx, &xrpc.Client{Host: "*"}, didr, hr, did) 995 + if err != nil { 996 + return "", err 997 + } 998 + 999 + cache.Add(did, &cachedHandle{ 1000 + Handle: h, 1001 + Valid: time.Now().Add(time.Minute * 10), 1002 + }) 1003 + 1004 + return h, nil 1005 + } 1006 + 978 1007 rsc := &events.RepoStreamCallbacks{ 979 1008 RepoCommit: func(evt *comatproto.SyncSubscribeRepos_Commit) error { 980 1009 if jsonfmt { ··· 1008 1037 } 1009 1038 var handle string 1010 1039 if resolveHandles { 1011 - h, _, err := api.ResolveDidToHandle(ctx, &xrpc.Client{Host: "*"}, didr, hr, evt.Repo) 1040 + h, err := resolveDid(ctx, evt.Repo) 1012 1041 if err != nil { 1013 1042 fmt.Println("failed to resolve handle: ", err) 1014 1043 } else {