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

Quick fix to ensure cache descriptors always return deferreds #6263

Merged
merged 3 commits into from
Oct 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/6263.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Change cache descriptors to always return deferreds.
2 changes: 1 addition & 1 deletion synapse/push/bulk_push_rule_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def _get_rules_for_event(self, event, context):
dict of user_id -> push_rules
"""
room_id = event.room_id
rules_for_room = self._get_rules_for_room(room_id)
rules_for_room = yield self._get_rules_for_room(room_id)

rules_by_user = yield rules_for_room.get_rules(event, context)

Expand Down
2 changes: 1 addition & 1 deletion synapse/storage/data_stores/main/roommember.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ def _get_joined_hosts(self, room_id, state_group, current_state_ids, state_entry
# See bulk_get_push_rules_for_room for how we work around this.
assert state_group is not None

cache = self._get_joined_hosts_cache(room_id)
cache = yield self._get_joined_hosts_cache(room_id)
joined_hosts = yield cache.get_destinations(state_entry)

return joined_hosts
Expand Down
9 changes: 4 additions & 5 deletions synapse/util/caches/descriptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ def _wrapped(*args, **kwargs):
if isinstance(cached_result_d, ObservableDeferred):
observer = cached_result_d.observe()
else:
observer = cached_result_d
observer = defer.succeed(cached_result_d)

except KeyError:
ret = defer.maybeDeferred(
Expand Down Expand Up @@ -482,9 +482,8 @@ class CacheListDescriptor(_CacheDescriptorBase):
Given a list of keys it looks in the cache to find any hits, then passes
the list of missing keys to the wrapped function.

Once wrapped, the function returns either a Deferred which resolves to
the list of results, or (if all results were cached), just the list of
results.
Once wrapped, the function returns a Deferred which resolves to the list
of results.
"""

def __init__(
Expand Down Expand Up @@ -618,7 +617,7 @@ def errback(f):
)
return make_deferred_yieldable(d)
else:
return results
return defer.succeed(results)

obj.__dict__[self.orig.__name__] = wrapped

Expand Down
4 changes: 2 additions & 2 deletions tests/util/caches/test_descriptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,9 @@ def fn(self, arg1, arg2):
self.assertEqual(len(obj.fn.cache.cache), 3)

r = obj.fn(1, 2)
self.assertEqual(r, ["spam", "eggs"])
self.assertEqual(r.result, ["spam", "eggs"])
r = obj.fn(1, 3)
self.assertEqual(r, ["chips"])
self.assertEqual(r.result, ["chips"])
obj.mock.assert_not_called()

def test_cache_iterable_with_sync_exception(self):
Expand Down