Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Remove unnecessary JSON whitespace stored for push rules
Browse files Browse the repository at this point in the history
  • Loading branch information
auscompgeek committed Jul 22, 2020
1 parent 1dd3679 commit c6ceb38
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
5 changes: 2 additions & 3 deletions synapse/storage/data_stores/main/event_push_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@

import logging

from canonicaljson import json

from twisted.internet import defer

from synapse.metrics.background_process_metrics import run_as_background_process
from synapse.storage._base import LoggingTransaction, SQLBaseStore, db_to_json
from synapse.storage.database import Database
from synapse.util import json_encoder
from synapse.util.caches.descriptors import cachedInlineCallbacks

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -51,7 +50,7 @@ def _serialize_action(actions, is_highlight):
else:
if actions == DEFAULT_NOTIF_ACTION:
return ""
return json.dumps(actions)
return json_encoder.encode(actions)


def _deserialize_action(actions, is_highlight):
Expand Down
9 changes: 4 additions & 5 deletions synapse/storage/data_stores/main/push_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import logging
from typing import List, Tuple, Union

from canonicaljson import json

from twisted.internet import defer

from synapse.push.baserules import list_with_base_rules
Expand All @@ -33,6 +31,7 @@
from synapse.storage.database import Database
from synapse.storage.push_rule import InconsistentRuleException, RuleNotFoundException
from synapse.storage.util.id_generators import ChainedIdGenerator
from synapse.util import json_encoder
from synapse.util.caches.descriptors import cachedInlineCallbacks, cachedList
from synapse.util.caches.stream_change_cache import StreamChangeCache

Expand Down Expand Up @@ -411,8 +410,8 @@ def add_push_rule(
before=None,
after=None,
):
conditions_json = json.dumps(conditions)
actions_json = json.dumps(actions)
conditions_json = json_encoder.encode(conditions)
actions_json = json_encoder.encode(actions)
with self._push_rules_stream_id_gen.get_next() as ids:
stream_id, event_stream_ordering = ids
if before or after:
Expand Down Expand Up @@ -681,7 +680,7 @@ def _set_push_rule_enabled_txn(

@defer.inlineCallbacks
def set_push_rule_actions(self, user_id, rule_id, actions, is_default_rule):
actions_json = json.dumps(actions)
actions_json = json_encoder.encode(actions)

def set_push_rule_actions_txn(txn, stream_id, event_stream_ordering):
if is_default_rule:
Expand Down

0 comments on commit c6ceb38

Please sign in to comment.