Merge branch 'develop' into matrix-org-hotfixes

This commit is contained in:
Richard van der Hoff 2018-07-12 12:09:25 +01:00
commit 195aae2f16
4 changed files with 37 additions and 9 deletions

1
changelog.d/3316.feature Normal file
View file

@ -0,0 +1 @@
Enforce the specified API for report_event

1
changelog.d/3521.feature Normal file
View file

@ -0,0 +1 @@
Cache optimisation for /sync requests

View file

@ -15,9 +15,17 @@
import logging
from six import string_types
from six.moves import http_client
from twisted.internet import defer
from synapse.http.servlet import RestServlet, parse_json_object_from_request
from synapse.api.errors import Codes, SynapseError
from synapse.http.servlet import (
RestServlet,
assert_params_in_request,
parse_json_object_from_request,
)
from ._base import client_v2_patterns
@ -42,12 +50,26 @@ class ReportEventRestServlet(RestServlet):
user_id = requester.user.to_string()
body = parse_json_object_from_request(request)
assert_params_in_request(body, ("reason", "score"))
if not isinstance(body["reason"], string_types):
raise SynapseError(
http_client.BAD_REQUEST,
"Param 'reason' must be a string",
Codes.BAD_JSON,
)
if not isinstance(body["score"], int):
raise SynapseError(
http_client.BAD_REQUEST,
"Param 'score' must be an integer",
Codes.BAD_JSON,
)
yield self.store.add_event_report(
room_id=room_id,
event_id=event_id,
user_id=user_id,
reason=body.get("reason"),
reason=body["reason"],
content=body,
received_ts=self.clock.time_msec(),
)

View file

@ -74,14 +74,18 @@ class StreamChangeCache(object):
assert type(stream_pos) is int
if stream_pos >= self._earliest_known_stream_pos:
not_known_entities = set(entities) - set(self._entity_to_key)
changed_entities = {
self._cache[k] for k in self._cache.islice(
start=self._cache.bisect_right(stream_pos),
)
}
result = (
{self._cache[k] for k in self._cache.islice(
start=self._cache.bisect_right(stream_pos))}
.intersection(entities)
.union(not_known_entities)
)
# we need to include entities which we don't know about, as well as
# those which are known to have changed since the stream pos.
result = {
e for e in entities
if e in changed_entities or e not in self._entity_to_key
}
self.metrics.inc_hits()
else: