chore: add twt_mentions table

This commit is contained in:
xuu 2025-03-30 21:32:49 -06:00
parent fc762f3bf3
commit aedc9245e5
Signed by: xuu
GPG Key ID: 8B3B0604F164E04F
2 changed files with 22 additions and 3 deletions

17
feed.go
View File

@ -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
}

View File

@ -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);