this repo has no description

fix cursor

Changed files
+13 -10
peruse
+13 -10
peruse/handle_wikidata_feed.go
···
"encoding/json"
"fmt"
"log/slog"
+
"strconv"
"strings"
"sync"
"time"
···
func (f *WikidataFeed) FeedSkeleton(e echo.Context, req FeedSkeletonRequest) error {
ctx := e.Request().Context()
-
cursor, err := getTimeBasedCursor(req)
-
if err != nil {
-
f.logger.Error("error getting cursor", "error", err)
-
return helpers.InputError(e, "FeedError", "Invalid cursor for feed")
+
var cursor int
+
if req.Cursor != "" {
+
cursor64, err := strconv.ParseInt(req.Cursor, 10, 32)
+
if err != nil {
+
f.logger.Error("error converting cursor", "error", err)
+
}
+
cursor = int(cursor64)
}
posts, err := f.getPosts(ctx)
···
return helpers.ServerError(e, "FeedError", "Unable to get posts for feed")
}
-
for i, p := range posts {
-
if p.CreatedAt == cursor {
-
posts = posts[i:]
-
break
-
}
+
if len(posts) < cursor {
+
cursor = len(posts)
}
+
+
posts = posts[cursor:]
if len(posts) > 30 {
posts = posts[:30]
···
})
}
-
newCursor := fmt.Sprintf("%d", posts[len(posts)-1].CreatedAt.UnixMilli())
+
newCursor := fmt.Sprintf("%d", cursor+len(posts))
return e.JSON(200, FeedSkeletonResponse{
Feed: items,