this repo has no description
1
fork

Configure Feed

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

feat: insert all records

+95 -13
+1 -10
consumer.go
··· 7 7 "net/http" 8 8 "net/url" 9 9 "os" 10 - "strings" 11 10 "time" 12 11 13 12 "github.com/bluesky-social/indigo/api/atproto" ··· 136 135 continue 137 136 } 138 137 139 - if !strings.HasPrefix(collection.String(), "app.bsky.") { 140 - continue 141 - } 142 - 143 - if err := p.handleCreate(ctx, *rec, evt.Time, evt.Rev, did.String(), collection.String(), rkey.String(), reccid.String()); err != nil { 138 + if err := p.handleCreate(ctx, *rec, evt.Time, evt.Rev, did.String(), collection.String(), rkey.String(), reccid.String(), fmt.Sprintf("%d", evt.Seq)); err != nil { 144 139 p.logger.Error("error handling create event", "error", err) 145 140 continue 146 141 } 147 142 case repomgr.EvtKindDeleteRecord: 148 - if !strings.HasPrefix(collection.String(), "app.bsky.") { 149 - continue 150 - } 151 - 152 143 if err := p.handleDelete(ctx, did.String(), collection.String(), rkey.String()); err != nil { 153 144 p.logger.Error("error handling delete event", "error", err) 154 145 continue
+31 -2
handle_create.go
··· 13 13 "github.com/haileyok/photocopy/models" 14 14 ) 15 15 16 - func (p *Photocopy) handleCreate(ctx context.Context, recb []byte, indexedAt, rev, did, collection, rkey, cid string) error { 17 - 16 + func (p *Photocopy) handleCreate(ctx context.Context, recb []byte, indexedAt, rev, did, collection, rkey, cid, seq string) error { 18 17 iat, err := dateparse.ParseAny(indexedAt) 19 18 if err != nil { 20 19 return err 20 + } 21 + 22 + if err := p.handleCreateRecord(ctx, did, rkey, collection, cid, recb, seq); err != nil { 23 + p.logger.Error("error creating record", "error", err) 21 24 } 22 25 23 26 switch collection { ··· 30 33 default: 31 34 return nil 32 35 } 36 + } 37 + 38 + func (p *Photocopy) handleCreateRecord(ctx context.Context, did, rkey, collection, cid string, raw []byte, seq string) error { 39 + var cat time.Time 40 + prkey, err := syntax.ParseTID(rkey) 41 + if err == nil { 42 + cat = prkey.Time() 43 + } else { 44 + cat = time.Now() 45 + } 46 + 47 + rec := models.Record{ 48 + Did: did, 49 + Rkey: rkey, 50 + Collection: collection, 51 + Cid: cid, 52 + Seq: seq, 53 + Raw: raw, 54 + CreatedAt: cat, 55 + } 56 + 57 + if err := p.inserters.recordsInserter.Insert(ctx, rec); err != nil { 58 + return err 59 + } 60 + 61 + return nil 33 62 } 34 63 35 64 func (p *Photocopy) handleCreatePost(ctx context.Context, rev string, recb []byte, uri, did, collection, rkey, cid string, indexedAt time.Time) error {
+13
handle_delete.go
··· 2 2 3 3 import ( 4 4 "context" 5 + "time" 6 + 7 + "github.com/haileyok/photocopy/models" 5 8 ) 6 9 7 10 func (p *Photocopy) handleDelete(ctx context.Context, did, collection, rkey string) error { 11 + del := models.Delete{ 12 + Did: did, 13 + Rkey: rkey, 14 + CreatedAt: time.Now(), 15 + } 16 + 17 + if err := p.inserters.deletesInserter.Insert(ctx, del); err != nil { 18 + return err 19 + } 20 + 8 21 return nil 9 22 }
-1
models.go
··· 1 - package photocopy
+9
models/delete.go
··· 1 + package models 2 + 3 + import "time" 4 + 5 + type Delete struct { 6 + Did string `ch:"did"` 7 + Rkey string `ch:"rkey"` 8 + CreatedAt time.Time `ch:"created_at"` 9 + }
+13
models/record.go
··· 1 + package models 2 + 3 + import "time" 4 + 5 + type Record struct { 6 + Did string `ch:"did"` 7 + Rkey string `ch:"rkey"` 8 + Collection string `ch:"collection"` 9 + Cid string `ch:"cid"` 10 + Seq string `ch:"seq"` 11 + Raw []byte `ch:"raw"` 12 + CreatedAt time.Time 13 + }
+28
photocopy.go
··· 34 34 interactionsInserter *clickhouse_inserter.Inserter 35 35 postsInserter *clickhouse_inserter.Inserter 36 36 plcInserter *clickhouse_inserter.Inserter 37 + recordsInserter *clickhouse_inserter.Inserter 38 + deletesInserter *clickhouse_inserter.Inserter 37 39 } 38 40 39 41 type Args struct { ··· 111 113 return nil, err 112 114 } 113 115 116 + ri, err := clickhouse_inserter.New(ctx, &clickhouse_inserter.Args{ 117 + PrometheusCounterPrefix: "photocopy_records", 118 + Histogram: insertionsHist, 119 + BatchSize: 1000, 120 + Logger: p.logger, 121 + Conn: conn, 122 + Query: "INSERT INTO records (did, rkey, collection, cid, seq, raw, created_at)", 123 + }) 124 + if err != nil { 125 + return nil, err 126 + } 127 + 128 + di, err := clickhouse_inserter.New(ctx, &clickhouse_inserter.Args{ 129 + PrometheusCounterPrefix: "photocopy_records", 130 + Histogram: insertionsHist, 131 + BatchSize: 1000, 132 + Logger: p.logger, 133 + Conn: conn, 134 + Query: "INSERT INTO deletes (did, rkey, created_at)", 135 + }) 136 + if err != nil { 137 + return nil, err 138 + } 139 + 114 140 is := &Inserters{ 115 141 followsInserter: fi, 116 142 postsInserter: pi, 117 143 interactionsInserter: ii, 144 + recordsInserter: ri, 145 + deletesInserter: di, 118 146 } 119 147 120 148 p.inserters = is