chore: fixes and import

This commit is contained in:
xuu committed 2025-03-29 17:09:18 -06:00
1 parent 84c3099be6
commit dab5a115cf
7 files changed
+254 -119

No files matched your search

+20 -31
View File
@@ -114,11 +114,12 @@ func httpServer(ctx context.Context, app *appState) error {
defer span.End()
args := make([]any, 0, 3)
uriarg := "state not in ('frozen', 'permanantly-dead')"
where := ``
uri := r.URL.Query().Get("uri")
if uri != "" {
feed_id := urlNS.UUID5(uri)
uriarg = "feed_id = ?"
where = "where feed_id = ?"
args = append(args, feed_id)
}
@@ -134,15 +135,7 @@ func httpServer(ctx context.Context, app *appState) error {
var end int64
err = db.QueryRowContext(ctx, `
select count(*) n from twts
JOIN (
SELECT
feed_id,
nick,
uri
FROM feeds
where `+uriarg+`
) using (feed_id)`, args...).Scan(&end)
select count(*) n from twts `+where, args...).Scan(&end)
span.RecordError(err)
if offset < 1 {
@@ -159,27 +152,29 @@ func httpServer(ctx context.Context, app *appState) error {
attribute.Int64("offset-start", offset-int64(limit)),
attribute.Int64("max", end),
))
qry := `
SELECT
feed_id,
hash,
conv,
nick,
uri,
coalesce(nick, 'nobody') nick,
coalesce(uri, 'https://empty.txt') uri,
text
FROM twts
JOIN (
SELECT
feed_id,
nick,
uri
FROM feeds
where ` + uriarg + `
left join (
select feed_id, nick, uri
from feeds
) using (feed_id)
order by ulid asc
limit ?
offset ?
`
where rowid in (
select rowid from twts
` + where +`
order by ulid asc
limit ?
offset ?
)
order by ulid asc`
fmt.Println(qry, args)
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
rows, err := db.QueryContext(
@@ -249,13 +244,7 @@ func httpServer(ctx context.Context, app *appState) error {
last_scan_on,
coalesce(last_twt_on, last_scan_on) last_twt_on
FROM feeds
left join (
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
) using (feed_id)
left join last_twt_on using (feed_id)
` + where + `
order by nick, uri
`