diff options
author | Erik Johnston <erik@matrix.org> | 2015-05-29 12:17:33 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2015-05-29 12:17:33 +0100 |
commit | a7b65bdedf512f646a3ca2478fb96a914856de35 (patch) | |
tree | 8b0336ae751d081a21b32c16f1cdb5d93f43e2fb /synapse/storage/events.py | |
parent | SYN-395: Fix CAPTCHA, don't double decode json (diff) | |
download | synapse-a7b65bdedf512f646a3ca2478fb96a914856de35.tar.xz |
Add config option to turn off freezing events. Use new encode_json api and ujson.loads
Diffstat (limited to '')
-rw-r--r-- | synapse/storage/events.py | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/synapse/storage/events.py b/synapse/storage/events.py index d2a010bd88..20a8d81794 100644 --- a/synapse/storage/events.py +++ b/synapse/storage/events.py @@ -17,7 +17,7 @@ from _base import SQLBaseStore, _RollbackButIsFineException from twisted.internet import defer, reactor -from synapse.events import FrozenEvent +from synapse.events import FrozenEvent, USE_FROZEN_DICTS from synapse.events.utils import prune_event from synapse.util.logcontext import preserve_context_over_deferred @@ -26,11 +26,11 @@ from synapse.api.constants import EventTypes from synapse.crypto.event_signing import compute_event_reference_hash from syutil.base64util import decode_base64 -from syutil.jsonutil import encode_canonical_json +from syutil.jsonutil import encode_json from contextlib import contextmanager import logging -import simplejson as json +import ujson as json logger = logging.getLogger(__name__) @@ -166,8 +166,9 @@ class EventsStore(SQLBaseStore): allow_none=True, ) - metadata_json = encode_canonical_json( - event.internal_metadata.get_dict() + metadata_json = encode_json( + event.internal_metadata.get_dict(), + using_frozen_dicts=USE_FROZEN_DICTS ).decode("UTF-8") # If we have already persisted this event, we don't need to do any @@ -235,12 +236,14 @@ class EventsStore(SQLBaseStore): "event_id": event.event_id, "room_id": event.room_id, "internal_metadata": metadata_json, - "json": encode_canonical_json(event_dict).decode("UTF-8"), + "json": encode_json( + event_dict, using_frozen_dicts=USE_FROZEN_DICTS + ).decode("UTF-8"), }, ) - content = encode_canonical_json( - event.content + content = encode_json( + event.content, using_frozen_dicts=USE_FROZEN_DICTS ).decode("UTF-8") vals = { @@ -266,8 +269,8 @@ class EventsStore(SQLBaseStore): ] } - vals["unrecognized_keys"] = encode_canonical_json( - unrec + vals["unrecognized_keys"] = encode_json( + unrec, using_frozen_dicts=USE_FROZEN_DICTS ).decode("UTF-8") sql = ( |