diff options
author | 2023-07-31 11:25:29 +0100 | |
---|---|---|
committer | 2023-07-31 11:25:29 +0100 | |
commit | ed2477ebea4c3ceec5949821f4950db9669a4a15 (patch) | |
tree | 1038d7abdfc787ddfc1febb326fd38775b189b85 /internal/api/client | |
parent | [bugfix/frontend] Decode URI component domain before showing on frontend (#2043) (diff) | |
download | gotosocial-ed2477ebea4c3ceec5949821f4950db9669a4a15.tar.xz |
[performance] cache follow, follow request and block ID lists (#2027)
Diffstat (limited to 'internal/api/client')
-rw-r--r-- | internal/api/client/blocks/blocks.go | 2 | ||||
-rw-r--r-- | internal/api/client/blocks/blocksget.go | 42 |
2 files changed, 18 insertions, 26 deletions
diff --git a/internal/api/client/blocks/blocks.go b/internal/api/client/blocks/blocks.go index bff9a068e..0eeee2bf1 100644 --- a/internal/api/client/blocks/blocks.go +++ b/internal/api/client/blocks/blocks.go @@ -30,8 +30,10 @@ const ( // MaxIDKey is the url query for setting a max ID to return MaxIDKey = "max_id" + // SinceIDKey is the url query for returning results newer than the given ID SinceIDKey = "since_id" + // LimitKey is for specifying maximum number of results to return. LimitKey = "limit" ) diff --git a/internal/api/client/blocks/blocksget.go b/internal/api/client/blocks/blocksget.go index 7aec8b334..505c33db8 100644 --- a/internal/api/client/blocks/blocksget.go +++ b/internal/api/client/blocks/blocksget.go @@ -18,14 +18,13 @@ package blocks import ( - "fmt" "net/http" - "strconv" "github.com/gin-gonic/gin" apiutil "github.com/superseriousbusiness/gotosocial/internal/api/util" "github.com/superseriousbusiness/gotosocial/internal/gtserror" "github.com/superseriousbusiness/gotosocial/internal/oauth" + "github.com/superseriousbusiness/gotosocial/internal/paging" ) // BlocksGETHandler swagger:operation GET /api/v1/blocks blocksGet @@ -104,31 +103,21 @@ func (m *Module) BlocksGETHandler(c *gin.Context) { return } - maxID := "" - maxIDString := c.Query(MaxIDKey) - if maxIDString != "" { - maxID = maxIDString - } - - sinceID := "" - sinceIDString := c.Query(SinceIDKey) - if sinceIDString != "" { - sinceID = sinceIDString - } - - limit := 20 - limitString := c.Query(LimitKey) - if limitString != "" { - i, err := strconv.ParseInt(limitString, 10, 32) - if err != nil { - err := fmt.Errorf("error parsing %s: %s", LimitKey, err) - apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1) - return - } - limit = int(i) + limit, errWithCode := apiutil.ParseLimit(c.Query(LimitKey), 20, 100, 2) + if err != nil { + apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1) + return } - resp, errWithCode := m.processor.BlocksGet(c.Request.Context(), authed, maxID, sinceID, limit) + resp, errWithCode := m.processor.BlocksGet( + c.Request.Context(), + authed.Account, + paging.Pager{ + SinceID: c.Query(SinceIDKey), + MaxID: c.Query(MaxIDKey), + Limit: limit, + }, + ) if errWithCode != nil { apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1) return @@ -137,5 +126,6 @@ func (m *Module) BlocksGETHandler(c *gin.Context) { if resp.LinkHeader != "" { c.Header("Link", resp.LinkHeader) } - c.JSON(http.StatusOK, resp.Accounts) + + c.JSON(http.StatusOK, resp.Items) } |