2019-05-14 16:59:21 +01:00
|
|
|
# Copyright 2019 New Vector Ltd
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
import logging
|
2022-03-30 11:45:32 -04:00
|
|
|
from typing import TYPE_CHECKING, Any, Dict, List, Optional
|
2019-05-14 16:59:21 +01:00
|
|
|
|
2019-05-14 16:59:21 +01:00
|
|
|
import attr
|
|
|
|
|
2020-12-30 08:09:53 -05:00
|
|
|
from synapse.types import JsonDict
|
2019-05-14 16:59:21 +01:00
|
|
|
|
2022-02-10 10:52:48 -05:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
from synapse.storage.databases.main import DataStore
|
|
|
|
|
2019-05-14 16:59:21 +01:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2022-01-13 08:49:28 -05:00
|
|
|
@attr.s(slots=True, auto_attribs=True)
|
2020-09-04 06:54:56 -04:00
|
|
|
class PaginationChunk:
|
2019-05-14 16:59:21 +01:00
|
|
|
"""Returned by relation pagination APIs.
|
|
|
|
|
|
|
|
Attributes:
|
2020-12-30 08:09:53 -05:00
|
|
|
chunk: The rows returned by pagination
|
|
|
|
next_batch: Token to fetch next set of results with, if
|
2019-05-14 16:59:21 +01:00
|
|
|
None then there are no more results.
|
2020-12-30 08:09:53 -05:00
|
|
|
prev_batch: Token to fetch previous set of results with, if
|
2019-05-14 16:59:21 +01:00
|
|
|
None then there are no previous results.
|
2019-05-14 16:59:21 +01:00
|
|
|
"""
|
|
|
|
|
2022-01-13 08:49:28 -05:00
|
|
|
chunk: List[JsonDict]
|
|
|
|
next_batch: Optional[Any] = None
|
|
|
|
prev_batch: Optional[Any] = None
|
2019-05-14 16:59:21 +01:00
|
|
|
|
2022-02-10 10:52:48 -05:00
|
|
|
async def to_dict(self, store: "DataStore") -> Dict[str, Any]:
|
2019-05-14 16:59:21 +01:00
|
|
|
d = {"chunk": self.chunk}
|
|
|
|
|
2019-05-14 16:59:21 +01:00
|
|
|
if self.next_batch:
|
2022-02-10 10:52:48 -05:00
|
|
|
d["next_batch"] = await self.next_batch.to_string(store)
|
2019-05-14 16:59:21 +01:00
|
|
|
|
|
|
|
if self.prev_batch:
|
2022-02-10 10:52:48 -05:00
|
|
|
d["prev_batch"] = await self.prev_batch.to_string(store)
|
2019-05-14 16:59:21 +01:00
|
|
|
|
2019-05-14 16:59:21 +01:00
|
|
|
return d
|