chore: fixes

This commit is contained in:
xuu 2025-03-31 10:49:36 -06:00
parent aedc9245e5
commit 69755e14d2
Signed by: xuu
GPG Key ID: 8B3B0604F164E04F
5 changed files with 35 additions and 36 deletions

12
feed.go
View File

@ -563,7 +563,7 @@ func (n TwtTime) Value() (driver.Value, error) {
} }
func makeULID(twt types.Twt) ulid.ULID { func makeULID(twt types.Twt) ulid.ULID {
text := fmt.Appendf(nil, "%s\t%+l", cmp.Or(twt.Twter().HashingURI, twt.Twter().URI), twt) text := fmt.Appendf(nil, "%s\t%+l", twt.Twter().URI, twt)
u := ulid.ULID{} u := ulid.ULID{}
u.SetTime(ulid.Timestamp(twt.Created())) u.SetTime(ulid.Timestamp(twt.Created()))
u.SetEntropy(sha3.SumSHAKE128(text, 10)) u.SetEntropy(sha3.SumSHAKE128(text, 10))
@ -608,14 +608,18 @@ func refreshLastTwt(ctx context.Context, db db) error {
qry := ` qry := `
delete from last_twt_on; delete from last_twt_on;
insert into last_twt_on insert into last_twt_on
select select distinct
feed_id, feed_id,
max(strftime('%Y-%m-%dT%H:%M:%fZ', (substring(text, 1, instr(text, ' ')-1)))) last_twt_on max(strftime('%Y-%m-%dT%H:%M:%fZ', (substring(text, 1, instr(text, ' ')-1)))) last_twt_on
from twts from twts
group by feed_id group by feed_id
on conflict(feed_id) do update set last_twt_on = excluded.last_twt_on; on conflict(feed_id);
delete from twt_mentions; delete from twt_mentions;
insert into twt_mentions select ulid, unhex(replace(trim(value,'{}'),'-','')) feed_id from twts, json_each(mentions); insert into twt_mentions
select distinct
ulid,
unhex(replace(trim(value,'{}'),'-','')) feed_id
from twts, json_each(mentions);
` `
var err error var err error
for _, stmt := range strings.Split(qry, ";") { for _, stmt := range strings.Split(qry, ";") {

View File

@ -38,8 +38,6 @@ var PREAMBLE_DOCS = func() lextwt.Comments {
return add(c, "") return add(c, "")
}() }()
func httpServer(ctx context.Context, app *appState) error { func httpServer(ctx context.Context, app *appState) error {
ctx, span := otel.Span(ctx) ctx, span := otel.Span(ctx)
defer span.End() defer span.End()
@ -150,7 +148,6 @@ func httpServer(ctx context.Context, app *appState) error {
args := make([]any, 0, 3) args := make([]any, 0, 3)
args = append(args, mention) args = append(args, mention)
limit := 100 limit := 100
if v, ok := strconv.Atoi(r.URL.Query().Get("limit")); ok == nil { if v, ok := strconv.Atoi(r.URL.Query().Get("limit")); ok == nil {
limit = v limit = v
@ -200,7 +197,6 @@ func httpServer(ctx context.Context, app *appState) error {
` `
fmt.Println(qry, args) fmt.Println(qry, args)
rows, err := db.QueryContext( rows, err := db.QueryContext(
ctx, qry, args..., ctx, qry, args...,
) )
@ -249,7 +245,6 @@ func httpServer(ctx context.Context, app *appState) error {
reg.WriteTo(w) reg.WriteTo(w)
}) })
http.HandleFunc("/api/plain/twt", func(w http.ResponseWriter, r *http.Request) { http.HandleFunc("/api/plain/twt", func(w http.ResponseWriter, r *http.Request) {
ctx, span := otel.Span(r.Context()) ctx, span := otel.Span(r.Context())
defer span.End() defer span.End()
@ -266,7 +261,7 @@ func httpServer(ctx context.Context, app *appState) error {
offset = v offset = v
} }
twts, end, err := func(uri string, limit int, offset int64, ) ([]types.Twt, int64, error) { twts, end, err := func(uri string, limit int, offset int64) ([]types.Twt, int64, error) {
args := make([]any, 0, 3) args := make([]any, 0, 3)
where := `where feed_id in (select feed_id from feeds where state != 'permanantly-dead')` where := `where feed_id in (select feed_id from feeds where state != 'permanantly-dead')`

View File

@ -35,7 +35,7 @@ CREATE INDEX if not exists twt_time on twts (ulid asc);
create table if not exists twt_mentions( create table if not exists twt_mentions(
feed_id blob, feed_id blob,
ulid blob, ulid blob,
primary key (feed_id) primary key (feed_id, ulid)
); );
CREATE INDEX if not exists twt_mention on twt_mentions (ulid asc); CREATE INDEX if not exists twt_mention on twt_mentions (ulid asc);