summary refs log tree commit diff
path: root/synapse/storage
diff options
context:
space:
mode:
authorRichard van der Hoff <1389908+richvdh@users.noreply.github.com>2019-07-24 13:16:18 +0100
committerGitHub <noreply@github.com>2019-07-24 13:16:18 +0100
commitf30a71a67b6605cb0f09975af3befc61090326bd (patch)
tree7ba88e6fbd4da96a38c16cd92e09547b6e36d3eb /synapse/storage
parentAdd a prometheus metric for active cache lookups. (#5750) (diff)
downloadsynapse-f30a71a67b6605cb0f09975af3befc61090326bd.tar.xz
Stop trying to fetch events with event_id=None. (#5753)
`None` is not a valid event id, so queuing up a database fetch for it seems
like a silly thing to do.

I considered making `get_event` return `None` if `event_id is None`, but then
its interaction with `allow_none` seemed uninituitive, and strong typing ftw.
Diffstat (limited to 'synapse/storage')
-rw-r--r--synapse/storage/events_worker.py5
-rw-r--r--synapse/storage/stats.py20
2 files changed, 15 insertions, 10 deletions
diff --git a/synapse/storage/events_worker.py b/synapse/storage/events_worker.py
index 44441957db..83fe4764d8 100644
--- a/synapse/storage/events_worker.py
+++ b/synapse/storage/events_worker.py
@@ -139,8 +139,11 @@ class EventsWorkerStore(SQLBaseStore):
                 If there is a mismatch, behave as per allow_none.
 
         Returns:
-            Deferred : A FrozenEvent.
+            Deferred[EventBase|None]
         """
+        if not isinstance(event_id, str):
+            raise TypeError("Invalid event event_id %r" % (event_id,))
+
         events = yield self.get_events_as_list(
             [event_id],
             check_redacted=check_redacted,
diff --git a/synapse/storage/stats.py b/synapse/storage/stats.py
index e893b05ee7..e13efed417 100644
--- a/synapse/storage/stats.py
+++ b/synapse/storage/stats.py
@@ -211,16 +211,18 @@ class StatsStore(StateDeltasStore):
             avatar_id = current_state_ids.get((EventTypes.RoomAvatar, ""))
             canonical_alias_id = current_state_ids.get((EventTypes.CanonicalAlias, ""))
 
+            event_ids = [
+                join_rules_id,
+                history_visibility_id,
+                encryption_id,
+                name_id,
+                topic_id,
+                avatar_id,
+                canonical_alias_id,
+            ]
+
             state_events = yield self.get_events(
-                [
-                    join_rules_id,
-                    history_visibility_id,
-                    encryption_id,
-                    name_id,
-                    topic_id,
-                    avatar_id,
-                    canonical_alias_id,
-                ]
+                [ev for ev in event_ids if ev is not None]
             )
 
             def _get_or_none(event_id, arg):