diff --git a/http.go b/http.go index 56e4363..afb4ef8 100644 --- a/http.go +++ b/http.go @@ -77,14 +77,14 @@ func httpServer(ctx context.Context, app *appState) error { rows, err := db.QueryContext( ctx, ` - SELECT - feed_id, - hash, - conv, + SELECT + feed_id, + hash, + conv, nick, uri, text - FROM twts + FROM twts JOIN ( SELECT feed_id, @@ -93,7 +93,7 @@ func httpServer(ctx context.Context, app *appState) error { FROM feeds ) using (feed_id) WHERE - hash = $1 or + hash = $1 or conv = $1 order by ulid asc`, hash, ) @@ -255,13 +255,14 @@ func httpServer(ctx context.Context, app *appState) error { if v, ok := strconv.Atoi(r.URL.Query().Get("limit")); ok == nil { limit = v } + limit = min(100, max(1, limit)) var offset int64 = 0 if v, ok := strconv.ParseInt(r.URL.Query().Get("offset"), 10, 64); ok == nil { offset = v } - twts, end, err := func(uri string, limit int, offset int64) ([]types.Twt, int64, error) { + twts, offset, end, err := func(uri string, limit int, offset int64) ([]types.Twt, int64, int64, error) { args := make([]any, 0, 3) where := `where feed_id in (select feed_id from feeds where state != 'permanantly-dead')` @@ -280,7 +281,6 @@ func httpServer(ctx context.Context, app *appState) error { offset += end } - limit = min(100, max(1, limit)) offset = max(1, offset) args = append(args, limit, offset-int64(limit)) @@ -320,7 +320,7 @@ func httpServer(ctx context.Context, app *appState) error { ) if err != nil { span.RecordError(err) - return nil, 0, err + return nil, 0, 0, err } defer rows.Close() @@ -338,15 +338,15 @@ func httpServer(ctx context.Context, app *appState) error { err = rows.Scan(&o.FeedID, &o.Hash, &o.Conv, &o.Nick, &o.URI, &o.Text) if err != nil { span.RecordError(err) - return nil, 0, err + return nil, 0, 0, err } twter := types.NewTwter(o.Nick, o.URI) twt, _ := lextwt.ParseLine(o.Text, &twter) twts = append(twts, twt) } - return twts, end, err - }(uri, limit, offset) + return twts, offset, end, err + } (uri, limit, offset) span.RecordError(err) preamble := add(PREAMBLE_DOCS, "twt range = 1 %d", end)