From aedc9245e5676e50dd4e43d77e60b9b1eeade6e8 Mon Sep 17 00:00:00 2001 From: xuu Date: Sun, 30 Mar 2025 21:32:49 -0600 Subject: [PATCH] chore: add twt_mentions table --- feed.go | 17 ++++++++++++++--- init.sql | 8 ++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/feed.go b/feed.go index 5a31b13..db98cf9 100644 --- a/feed.go +++ b/feed.go @@ -605,14 +605,25 @@ func chunk(args []any, qry func(int) (string, int), maxArgs int) iter.Seq2[strin } func refreshLastTwt(ctx context.Context, db db) error { - _, err := db.ExecContext(ctx, ` + qry := ` + delete from last_twt_on; insert into last_twt_on select feed_id, max(strftime('%Y-%m-%dT%H:%M:%fZ', (substring(text, 1, instr(text, ' ')-1)))) last_twt_on from twts group by feed_id - on conflict do update set last_twt_on = excluded.last_twt_on; -`) + on conflict(feed_id) do update set last_twt_on = excluded.last_twt_on; + delete from twt_mentions; + insert into twt_mentions select ulid, unhex(replace(trim(value,'{}'),'-','')) feed_id from twts, json_each(mentions); + ` + var err error + for _, stmt := range strings.Split(qry, ";") { + _, err = db.ExecContext(ctx, stmt) + if err != nil { + return err + } + } + return err } diff --git a/init.sql b/init.sql index cd279b4..1b6ceef 100644 --- a/init.sql +++ b/init.sql @@ -31,3 +31,11 @@ create table if not exists last_twt_on( ); CREATE INDEX if not exists twt_time on twts (ulid asc); + +create table if not exists twt_mentions( + feed_id blob, + ulid blob, + primary key (feed_id) +); + +CREATE INDEX if not exists twt_mention on twt_mentions (ulid asc);