chore: fix twts
This commit is contained in:
parent
69755e14d2
commit
e58cd8e3f1
24
http.go
24
http.go
@ -77,14 +77,14 @@ func httpServer(ctx context.Context, app *appState) error {
|
|||||||
|
|
||||||
rows, err := db.QueryContext(
|
rows, err := db.QueryContext(
|
||||||
ctx, `
|
ctx, `
|
||||||
SELECT
|
SELECT
|
||||||
feed_id,
|
feed_id,
|
||||||
hash,
|
hash,
|
||||||
conv,
|
conv,
|
||||||
nick,
|
nick,
|
||||||
uri,
|
uri,
|
||||||
text
|
text
|
||||||
FROM twts
|
FROM twts
|
||||||
JOIN (
|
JOIN (
|
||||||
SELECT
|
SELECT
|
||||||
feed_id,
|
feed_id,
|
||||||
@ -93,7 +93,7 @@ func httpServer(ctx context.Context, app *appState) error {
|
|||||||
FROM feeds
|
FROM feeds
|
||||||
) using (feed_id)
|
) using (feed_id)
|
||||||
WHERE
|
WHERE
|
||||||
hash = $1 or
|
hash = $1 or
|
||||||
conv = $1
|
conv = $1
|
||||||
order by ulid asc`, hash,
|
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 {
|
if v, ok := strconv.Atoi(r.URL.Query().Get("limit")); ok == nil {
|
||||||
limit = v
|
limit = v
|
||||||
}
|
}
|
||||||
|
limit = min(100, max(1, limit))
|
||||||
|
|
||||||
var offset int64 = 0
|
var offset int64 = 0
|
||||||
if v, ok := strconv.ParseInt(r.URL.Query().Get("offset"), 10, 64); ok == nil {
|
if v, ok := strconv.ParseInt(r.URL.Query().Get("offset"), 10, 64); ok == nil {
|
||||||
offset = v
|
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)
|
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')`
|
||||||
|
|
||||||
@ -280,7 +281,6 @@ func httpServer(ctx context.Context, app *appState) error {
|
|||||||
offset += end
|
offset += end
|
||||||
}
|
}
|
||||||
|
|
||||||
limit = min(100, max(1, limit))
|
|
||||||
offset = max(1, offset)
|
offset = max(1, offset)
|
||||||
|
|
||||||
args = append(args, limit, offset-int64(limit))
|
args = append(args, limit, offset-int64(limit))
|
||||||
@ -320,7 +320,7 @@ func httpServer(ctx context.Context, app *appState) error {
|
|||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
span.RecordError(err)
|
span.RecordError(err)
|
||||||
return nil, 0, err
|
return nil, 0, 0, err
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
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)
|
err = rows.Scan(&o.FeedID, &o.Hash, &o.Conv, &o.Nick, &o.URI, &o.Text)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
span.RecordError(err)
|
span.RecordError(err)
|
||||||
return nil, 0, err
|
return nil, 0, 0, err
|
||||||
}
|
}
|
||||||
twter := types.NewTwter(o.Nick, o.URI)
|
twter := types.NewTwter(o.Nick, o.URI)
|
||||||
twt, _ := lextwt.ParseLine(o.Text, &twter)
|
twt, _ := lextwt.ParseLine(o.Text, &twter)
|
||||||
twts = append(twts, twt)
|
twts = append(twts, twt)
|
||||||
}
|
}
|
||||||
|
|
||||||
return twts, end, err
|
return twts, offset, end, err
|
||||||
}(uri, limit, offset)
|
} (uri, limit, offset)
|
||||||
span.RecordError(err)
|
span.RecordError(err)
|
||||||
|
|
||||||
preamble := add(PREAMBLE_DOCS, "twt range = 1 %d", end)
|
preamble := add(PREAMBLE_DOCS, "twt range = 1 %d", end)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user