Support pagination tokens from /sync and /messages in the relations API. (#11952)

This commit is contained in:
Patrick Cloke 2022-02-10 10:52:48 -05:00 committed by GitHub
parent 337f38cac3
commit df36945ff0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 217 additions and 53 deletions

View file

@ -13,13 +13,16 @@
# limitations under the License.
import logging
from typing import Any, Dict, List, Optional, Tuple
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple
import attr
from synapse.api.errors import SynapseError
from synapse.types import JsonDict
if TYPE_CHECKING:
from synapse.storage.databases.main import DataStore
logger = logging.getLogger(__name__)
@ -39,14 +42,14 @@ class PaginationChunk:
next_batch: Optional[Any] = None
prev_batch: Optional[Any] = None
def to_dict(self) -> Dict[str, Any]:
async def to_dict(self, store: "DataStore") -> Dict[str, Any]:
d = {"chunk": self.chunk}
if self.next_batch:
d["next_batch"] = self.next_batch.to_string()
d["next_batch"] = await self.next_batch.to_string(store)
if self.prev_batch:
d["prev_batch"] = self.prev_batch.to_string()
d["prev_batch"] = await self.prev_batch.to_string(store)
return d
@ -75,7 +78,7 @@ class RelationPaginationToken:
except ValueError:
raise SynapseError(400, "Invalid relation pagination token")
def to_string(self) -> str:
async def to_string(self, store: "DataStore") -> str:
return "%d-%d" % (self.topological, self.stream)
def as_tuple(self) -> Tuple[Any, ...]:
@ -105,7 +108,7 @@ class AggregationPaginationToken:
except ValueError:
raise SynapseError(400, "Invalid aggregation pagination token")
def to_string(self) -> str:
async def to_string(self, store: "DataStore") -> str:
return "%d-%d" % (self.count, self.stream)
def as_tuple(self) -> Tuple[Any, ...]: