Low-latency AT Protocol interaction indexer.
20

Configure Feed

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

getBackLinkDids: add cursor pagination

Aly Raffauf (Jul 2, 2026, 10:47 PM EDT) 4079f2d0 2d9bc36e

+26 -5
+21 -2
internal/api/dids.go
··· 1 1 package api 2 2 3 3 import ( 4 + "encoding/base64" 4 5 "encoding/json" 5 6 "log" 6 7 "net/http" ··· 10 11 type backlinkDidsResponse struct { 11 12 Total uint64 `json:"total"` 12 13 LinkingDids []string `json:"linking_dids"` 14 + Cursor *string `json:"cursor"` 13 15 } 14 16 15 17 func (s *Server) GetBacklinkDids(w http.ResponseWriter, r *http.Request) { ··· 21 23 http.Error(w, err.Error(), http.StatusBadRequest) 22 24 return 23 25 } 26 + 24 27 25 28 limit := uint64(100) 26 29 if raw := r.URL.Query().Get("limit"); raw != "" { ··· 32 35 limit = parsed 33 36 } 34 37 35 - total, dids, err := s.Store.DistinctBacklinkDids(r.Context(), subject, collection, path, limit) 38 + after := "" 39 + if raw := r.URL.Query().Get("cursor"); raw != "" { 40 + decoded, err := base64.StdEncoding.DecodeString(raw) 41 + if err != nil { 42 + http.Error(w, "invalid cursor", http.StatusBadRequest) 43 + return 44 + } 45 + after = string(decoded) 46 + } 47 + 48 + total, dids, err := s.Store.DistinctBacklinkDids(r.Context(), subject, collection, path, after, limit) 36 49 if err != nil { 37 50 log.Println("distinct backlink dids:", err) 38 51 http.Error(w, "internal error", http.StatusInternalServerError) 39 52 return 40 53 } 41 54 55 + var cursor *string 56 + if uint64(len(dids)) == limit { 57 + encoded := base64.StdEncoding.EncodeToString([]byte(dids[len(dids)-1])) 58 + cursor = &encoded 59 + } 60 + 42 61 w.Header().Set("Content-Type", "application/json") 43 - json.NewEncoder(w).Encode(backlinkDidsResponse{Total: total, LinkingDids: dids}) 62 + json.NewEncoder(w).Encode(backlinkDidsResponse{Total: total, LinkingDids: dids, Cursor: cursor}) 44 63 }
+5 -3
internal/store/query.go
··· 19 19 return total, nil 20 20 } 21 21 22 - func (s *Store) DistinctBacklinkDids(ctx context.Context, target, collection, fieldPath string, limit uint64) (total uint64, dids []string, err error) { 22 + func (s *Store) DistinctBacklinkDids(ctx context.Context, target, collection, fieldPath string, after string, limit uint64) (total uint64, dids []string, err error) { 23 23 err = s.db.QueryRowContext(ctx, 24 24 `SELECT COUNT(DISTINCT actor_did) FROM links WHERE target = ? AND collection = ? AND field_path = ?`, 25 25 target, collection, fieldPath, ··· 29 29 } 30 30 31 31 rows, err := s.db.QueryContext(ctx, 32 - `SELECT DISTINCT actor_did FROM links WHERE target = ? AND collection = ? AND field_path = ? LIMIT ?`, 33 - target, collection, fieldPath, limit, 32 + `SELECT DISTINCT actor_did FROM links 33 + WHERE target = ? AND collection = ? AND field_path = ? AND actor_did > ? 34 + ORDER BY actor_did LIMIT ?`, 35 + target, collection, fieldPath, after, limit, 34 36 ) 35 37 if err != nil { 36 38 return 0, nil, fmt.Errorf("query distinct dids: %w", err)