mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-16 11:23:11 -06:00
Fix PaginationTokens
This commit is contained in:
parent
2541946c1f
commit
5f791f5e42
|
|
@ -81,7 +81,10 @@ func Setup(
|
||||||
})).Methods(http.MethodGet, http.MethodOptions)
|
})).Methods(http.MethodGet, http.MethodOptions)
|
||||||
|
|
||||||
r0mux.Handle("/rooms/{roomID}/messages", common.MakeAuthAPI("room_messages", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
r0mux.Handle("/rooms/{roomID}/messages", common.MakeAuthAPI("room_messages", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
||||||
vars := mux.Vars(req)
|
vars, err := common.URLDecodeMapValues(mux.Vars(req))
|
||||||
|
if err != nil {
|
||||||
|
return util.ErrorResponse(err)
|
||||||
|
}
|
||||||
return OnIncomingMessagesRequest(req, syncDB, vars["roomID"], federation, queryAPI, cfg)
|
return OnIncomingMessagesRequest(req, syncDB, vars["roomID"], federation, queryAPI, cfg)
|
||||||
})).Methods(http.MethodGet, http.MethodOptions)
|
})).Methods(http.MethodGet, http.MethodOptions)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -566,12 +566,11 @@ func (d *SyncServerDatasource) getResponseWithPDUsForCompleteSync(
|
||||||
defer common.EndTransaction(txn, &succeeded)
|
defer common.EndTransaction(txn, &succeeded)
|
||||||
|
|
||||||
// Get the current sync position which we will base the sync response on.
|
// Get the current sync position which we will base the sync response on.
|
||||||
/*
|
toPos, err = d.syncPositionTx(ctx, txn)
|
||||||
toPos, err = d.syncPositionTx(ctx, txn)
|
if err != nil {
|
||||||
if err != nil {
|
return
|
||||||
return
|
}
|
||||||
}
|
|
||||||
*/
|
|
||||||
// Get the current stream position which we will base the sync response on.
|
// Get the current stream position which we will base the sync response on.
|
||||||
pos, err := d.syncStreamPositionTx(ctx, txn)
|
pos, err := d.syncStreamPositionTx(ctx, txn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -628,6 +627,7 @@ func (d *SyncServerDatasource) getResponseWithPDUsForCompleteSync(
|
||||||
jr.Timeline.PrevBatch = types.NewPaginationTokenFromTypeAndPosition(
|
jr.Timeline.PrevBatch = types.NewPaginationTokenFromTypeAndPosition(
|
||||||
types.PaginationTokenTypeTopology, backwardTopologyPos, 0,
|
types.PaginationTokenTypeTopology, backwardTopologyPos, 0,
|
||||||
).String()
|
).String()
|
||||||
|
// TODO: do we want short-form here? adds complexity elsewhere
|
||||||
if prevPDUPos := recentStreamEvents[0].StreamPosition - 1; prevPDUPos > 0 {
|
if prevPDUPos := recentStreamEvents[0].StreamPosition - 1; prevPDUPos > 0 {
|
||||||
// Use the short form of batch token for prev_batch
|
// Use the short form of batch token for prev_batch
|
||||||
jr.Timeline.PrevBatch = strconv.FormatInt(int64(prevPDUPos), 10)
|
jr.Timeline.PrevBatch = strconv.FormatInt(int64(prevPDUPos), 10)
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ func newSyncRequest(req *http.Request, device authtypes.Device) (*syncRequest, e
|
||||||
timeout := getTimeout(req.URL.Query().Get("timeout"))
|
timeout := getTimeout(req.URL.Query().Get("timeout"))
|
||||||
fullState := req.URL.Query().Get("full_state")
|
fullState := req.URL.Query().Get("full_state")
|
||||||
wantFullState := fullState != "" && fullState != "false"
|
wantFullState := fullState != "" && fullState != "false"
|
||||||
since, err := getSyncStreamPosition(req.URL.Query().Get("since"))
|
since, err := getPaginationToken(req.URL.Query().Get("since"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -82,11 +82,11 @@ func getTimeout(timeoutMS string) time.Duration {
|
||||||
// getPaginationToken tries to parse a 'since' token taken from the API to a
|
// getPaginationToken tries to parse a 'since' token taken from the API to a
|
||||||
// pagination token. If the string is empty then (nil, nil) is returned.
|
// pagination token. If the string is empty then (nil, nil) is returned.
|
||||||
// Returns an error if the parsed token's type isn't types.PaginationTokenTypeStream.
|
// Returns an error if the parsed token's type isn't types.PaginationTokenTypeStream.
|
||||||
func getPaginationToken(since string) (*types.StreamPosition, error) {
|
func getSyncStreamPosition(since string) (*types.StreamPosition, error) {
|
||||||
if since == "" {
|
if since == "" {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
p, err := types.NewPaginationTokenFromString(since)
|
p, err := getPaginationToken(since)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -101,15 +101,10 @@ func getPaginationToken(since string) (*types.StreamPosition, error) {
|
||||||
// There are two forms of tokens: The full length form containing all PDU and EDU
|
// There are two forms of tokens: The full length form containing all PDU and EDU
|
||||||
// positions separated by "_", and the short form containing only the PDU
|
// positions separated by "_", and the short form containing only the PDU
|
||||||
// position. Short form can be used for, e.g., `prev_batch` tokens.
|
// position. Short form can be used for, e.g., `prev_batch` tokens.
|
||||||
func getSyncStreamPosition(since string) (*types.PaginationToken, error) {
|
func getPaginationToken(since string) (*types.PaginationToken, error) {
|
||||||
if since == "" {
|
if since == "" {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
pos, err := types.NewPaginationTokenFromString(since)
|
return types.NewPaginationTokenFromString(since)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return pos, nil
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -76,12 +76,18 @@ func NewPaginationTokenFromString(s string) (p *PaginationToken, err error) {
|
||||||
// Check if the type is among the known ones.
|
// Check if the type is among the known ones.
|
||||||
p.Type = PaginationTokenType(s[:1])
|
p.Type = PaginationTokenType(s[:1])
|
||||||
if p.Type != PaginationTokenTypeStream && p.Type != PaginationTokenTypeTopology {
|
if p.Type != PaginationTokenTypeStream && p.Type != PaginationTokenTypeTopology {
|
||||||
err = ErrInvalidPaginationTokenType
|
if pduPos, perr := strconv.ParseInt(s, 10, 64); perr != nil {
|
||||||
return
|
return nil, ErrInvalidPaginationTokenType
|
||||||
|
} else {
|
||||||
|
// TODO: should this be topograpical?
|
||||||
|
p.Type = PaginationTokenTypeTopology
|
||||||
|
p.PDUPosition = StreamPosition(pduPos)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse the token (aka position).
|
// Parse the token (aka position).
|
||||||
positions := strings.Split(s[:1], "_")
|
positions := strings.Split(s[1:], "_")
|
||||||
|
|
||||||
// Try to get the PDU position.
|
// Try to get the PDU position.
|
||||||
if len(positions) >= 1 {
|
if len(positions) >= 1 {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue