summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2017-02-14 16:54:37 +0000
committerErik Johnston <erik@matrix.org>2017-02-16 14:47:11 +0000
commit502ae6c663e9b96950d1b474fbec7cf200e4e8a1 (patch)
tree0f897ad0448c65d32a96f1e567e4ed5f6e13bdd7
parentStore the default push actions in a more efficient manner (diff)
downloadsynapse-502ae6c663e9b96950d1b474fbec7cf200e4e8a1.tar.xz
Comment
-rw-r--r--synapse/storage/event_push_actions.py21
1 files changed, 14 insertions, 7 deletions
diff --git a/synapse/storage/event_push_actions.py b/synapse/storage/event_push_actions.py
index db20b7de20..ea6722df63 100644
--- a/synapse/storage/event_push_actions.py
+++ b/synapse/storage/event_push_actions.py
@@ -26,30 +26,37 @@ import ujson as json
 logger = logging.getLogger(__name__)
 
 
-DEFAULT_NOTIF_ACITON = ["notify", {"set_tweak": "highlight", "value": False}]
-DEFAULT_HIGHLIGHT_ACITON = [
+DEFAULT_NOTIF_ACTION = ["notify", {"set_tweak": "highlight", "value": False}]
+DEFAULT_HIGHLIGHT_ACTION = [
     "notify", {"set_tweak": "sound", "value": "default"}, {"set_tweak": "highlight"}
 ]
 
 
 def _serialize_action(actions, is_highlight):
+    """Custom serializer for actions. This allows us to "compress" common actions.
+
+    We use the fact that most users have the same actions for notifs (and for
+    highlights). We replaces these default actions with the emtpy string.
+    """
     if is_highlight:
-        if actions == DEFAULT_HIGHLIGHT_ACITON:
-            return ""
+        if actions == DEFAULT_HIGHLIGHT_ACTION:
+            return ""  # We use empty string as the column is non-NULL
     else:
-        if actions == DEFAULT_NOTIF_ACITON:
+        if actions == DEFAULT_NOTIF_ACTION:
             return ""
     return json.dumps(actions)
 
 
 def _deserialize_action(actions, is_highlight):
+    """Custom deserializer for actions. This allows us to "compress" common actions
+    """
     if actions:
         return json.loads(actions)
 
     if is_highlight:
-        return DEFAULT_HIGHLIGHT_ACITON
+        return DEFAULT_HIGHLIGHT_ACTION
     else:
-        return DEFAULT_NOTIF_ACITON
+        return DEFAULT_NOTIF_ACTION
 
 
 class EventPushActionsStore(SQLBaseStore):