Move parsing of tokens out of storage layer

This commit is contained in:
Erik Johnston 2019-05-16 14:24:58 +01:00
parent 2c662ddde4
commit 7a7eba8302
2 changed files with 21 additions and 14 deletions

View File

@ -32,6 +32,7 @@ from synapse.http.servlet import (
parse_string,
)
from synapse.rest.client.transactions import HttpTransactionCache
from synapse.storage.relations import AggregationPaginationToken, RelationPaginationToken
from ._base import client_v2_patterns
@ -149,6 +150,12 @@ class RelationPaginationServlet(RestServlet):
from_token = parse_string(request, "from")
to_token = parse_string(request, "to")
if from_token:
from_token = RelationPaginationToken.from_string(from_token)
if to_token:
to_token = RelationPaginationToken.from_string(to_token)
result = yield self.store.get_relations_for_event(
event_id=parent_id,
relation_type=relation_type,
@ -221,6 +228,12 @@ class RelationAggregationPaginationServlet(RestServlet):
from_token = parse_string(request, "from")
to_token = parse_string(request, "to")
if from_token:
from_token = AggregationPaginationToken.from_string(from_token)
if to_token:
to_token = AggregationPaginationToken.from_string(to_token)
res = yield self.store.get_aggregation_groups_for_event(
event_id=parent_id,
event_type=event_type,
@ -289,6 +302,12 @@ class RelationAggregationGroupPaginationServlet(RestServlet):
from_token = parse_string(request, "from")
to_token = parse_string(request, "to")
if from_token:
from_token = RelationPaginationToken.from_string(from_token)
if to_token:
to_token = RelationPaginationToken.from_string(to_token)
result = yield self.store.get_relations_for_event(
event_id=parent_id,
relation_type=relation_type,

View File

@ -54,7 +54,7 @@ class PaginationChunk(object):
return d
@attr.s
@attr.s(frozen=True, slots=True)
class RelationPaginationToken(object):
"""Pagination token for relation pagination API.
@ -85,7 +85,7 @@ class RelationPaginationToken(object):
return attr.astuple(self)
@attr.s
@attr.s(frozen=True, slots=True)
class AggregationPaginationToken(object):
"""Pagination token for relation aggregation pagination API.
@ -151,12 +151,6 @@ class RelationsWorkerStore(SQLBaseStore):
requested. The rows are of the form `{"event_id": "..."}`.
"""
if from_token:
from_token = RelationPaginationToken.from_string(from_token)
if to_token:
to_token = RelationPaginationToken.from_string(to_token)
where_clause = ["relates_to_id = ?"]
where_args = [event_id]
@ -258,12 +252,6 @@ class RelationsWorkerStore(SQLBaseStore):
match. Each row is a dict with `type`, `key` and `count` fields.
"""
if from_token:
from_token = AggregationPaginationToken.from_string(from_token)
if to_token:
to_token = AggregationPaginationToken.from_string(to_token)
where_clause = ["relates_to_id = ?", "relation_type = ?"]
where_args = [event_id, RelationTypes.ANNOTATION]