Skip to content

Commit

Permalink
Track CV labels in Store
Browse files Browse the repository at this point in the history
  • Loading branch information
ericvolp12 committed Sep 15, 2024
1 parent 864ba66 commit 62f3276
Show file tree
Hide file tree
Showing 8 changed files with 242 additions and 12 deletions.
9 changes: 8 additions & 1 deletion cmd/indexer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,14 @@ func (index *Index) IndexImages(ctx context.Context, pageSize int32) {
err = index.PostRegistry.AddPostLabel(ctx, result.Meta.PostID, result.Meta.ActorDID, postLabel)
if err != nil {
logger.Error("Failed to add label to post", "error", err)
continue
}
err = index.Store.Queries.CreateRecentPostLabel(ctx, store_queries.CreateRecentPostLabelParams{
ActorDid: result.Meta.ActorDID,
Rkey: result.Meta.PostID,
Label: postLabel,
})
if err != nil {
logger.Error("Failed to create recent post label", "error", err)
}
}
}(result)
Expand Down
4 changes: 4 additions & 0 deletions pkg/consumer/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@ func (c *Consumer) TrimRecentPosts(ctx context.Context, maxAge time.Duration) er
if err != nil {
c.Logger.Error("failed to trim TQSP feed", "error", err)
}
err = c.Store.Queries.TrimRecentPostLabels(ctx, oldestRkey)
if err != nil {
c.Logger.Error("failed to trim recent post labels", "error", err)
}

postsTrimmed.WithLabelValues(c.SocketURL).Add(float64(numDeleted))

Expand Down
10 changes: 0 additions & 10 deletions pkg/consumer/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,16 +231,6 @@ func (c *Consumer) HandleCreatePost(ctx context.Context, repo, rkey string, inde
}
}

// Create a Sentiment Job for the post
err = c.Store.Queries.CreateSentimentJob(ctx, store_queries.CreateSentimentJobParams{
ActorDid: repo,
Rkey: rkey,
CreatedAt: recCreatedAt,
})
if err != nil {
log.Errorf("failed to create sentiment job: %+v", err)
}

// Create images for the post
if rec.Embed != nil && rec.Embed.EmbedImages != nil {
for _, img := range rec.Embed.EmbedImages.Images {
Expand Down
27 changes: 27 additions & 0 deletions pkg/consumer/store/queries/recent_post_labels.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-- name: CreateRecentPostLabel :exec
INSERT INTO recent_post_labels(actor_did, rkey, label)
VALUES ($1, $2, $3);
-- name: DeleteRecentPostLabel :exec
DELETE FROM recent_post_labels
WHERE actor_did = $1
AND rkey = $2
AND label = $3;
-- name: ListRecentPostLabels :many
SELECT label
FROM recent_post_labels
WHERE actor_did = $1
AND rkey = $2
ORDER BY label ASC;
-- name: ListRecentPostsByLabelHot :many
SELECT l.actor_did,
l.rkey
FROM recent_post_labels l
JOIN recent_posts_with_score rp ON l.actor_did = rp.actor_did
AND l.rkey = rp.rkey
WHERE label = $1
AND score < coalesce(sqlc.narg('score')::float, 100000)
ORDER BY score DESC
LIMIT $2;
-- name: TrimRecentPostLabels :exec
DELETE FROM recent_post_labels
WHERE rkey < $1;
11 changes: 10 additions & 1 deletion pkg/consumer/store/schema/feeds.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ CREATE TABLE pins (
rkey TEXT NOT NULL
);
CREATE UNIQUE INDEX pins_pk ON pins (actor_did, rkey DESC);
-- Label Feeds
-- Actor Label Feeds
CREATE TABLE actor_labels (
actor_did TEXT NOT NULL,
label TEXT NOT NULL,
Expand All @@ -22,3 +22,12 @@ CREATE TABLE tqsp (
PRIMARY KEY (actor_did, rkey)
);
CREATE INDEX tqsp_paging_idx ON tqsp (rkey DESC);
-- Post Label Feeds
CREATE TABLE recent_post_labels (
actor_did TEXT NOT NULL,
rkey TEXT NOT NULL,
label TEXT NOT NULL,
PRIMARY KEY (actor_did, rkey, label)
);
CREATE INDEX recent_post_labels_label_idx ON recent_post_labels (label);
CREATE INDEX recent_post_labels_paging_idx ON recent_post_labels (rkey DESC);
50 changes: 50 additions & 0 deletions pkg/consumer/store/store_queries/db.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions pkg/consumer/store/store_queries/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 62f3276

Please sign in to comment.