mirror of
https://mau.dev/maunium/synapse.git
synced 2024-12-15 02:53:51 +01:00
Merge pull request #6263 from matrix-org/erikj/caches_return_deferreds
Quick fix to ensure cache descriptors always return deferreds
This commit is contained in:
commit
561133c3c5
5 changed files with 9 additions and 9 deletions
1
changelog.d/6263.misc
Normal file
1
changelog.d/6263.misc
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Change cache descriptors to always return deferreds.
|
|
@ -79,7 +79,7 @@ class BulkPushRuleEvaluator(object):
|
||||||
dict of user_id -> push_rules
|
dict of user_id -> push_rules
|
||||||
"""
|
"""
|
||||||
room_id = event.room_id
|
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)
|
rules_by_user = yield rules_for_room.get_rules(event, context)
|
||||||
|
|
||||||
|
|
|
@ -720,7 +720,7 @@ class RoomMemberWorkerStore(EventsWorkerStore):
|
||||||
# See bulk_get_push_rules_for_room for how we work around this.
|
# See bulk_get_push_rules_for_room for how we work around this.
|
||||||
assert state_group is not None
|
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)
|
joined_hosts = yield cache.get_destinations(state_entry)
|
||||||
|
|
||||||
return joined_hosts
|
return joined_hosts
|
||||||
|
|
|
@ -438,7 +438,7 @@ class CacheDescriptor(_CacheDescriptorBase):
|
||||||
if isinstance(cached_result_d, ObservableDeferred):
|
if isinstance(cached_result_d, ObservableDeferred):
|
||||||
observer = cached_result_d.observe()
|
observer = cached_result_d.observe()
|
||||||
else:
|
else:
|
||||||
observer = cached_result_d
|
observer = defer.succeed(cached_result_d)
|
||||||
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
ret = defer.maybeDeferred(
|
ret = defer.maybeDeferred(
|
||||||
|
@ -482,9 +482,8 @@ class CacheListDescriptor(_CacheDescriptorBase):
|
||||||
Given a list of keys it looks in the cache to find any hits, then passes
|
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.
|
the list of missing keys to the wrapped function.
|
||||||
|
|
||||||
Once wrapped, the function returns either a Deferred which resolves to
|
Once wrapped, the function returns a Deferred which resolves to the list
|
||||||
the list of results, or (if all results were cached), just the list of
|
of results.
|
||||||
results.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
|
@ -618,7 +617,7 @@ class CacheListDescriptor(_CacheDescriptorBase):
|
||||||
)
|
)
|
||||||
return make_deferred_yieldable(d)
|
return make_deferred_yieldable(d)
|
||||||
else:
|
else:
|
||||||
return results
|
return defer.succeed(results)
|
||||||
|
|
||||||
obj.__dict__[self.orig.__name__] = wrapped
|
obj.__dict__[self.orig.__name__] = wrapped
|
||||||
|
|
||||||
|
|
|
@ -325,9 +325,9 @@ class DescriptorTestCase(unittest.TestCase):
|
||||||
self.assertEqual(len(obj.fn.cache.cache), 3)
|
self.assertEqual(len(obj.fn.cache.cache), 3)
|
||||||
|
|
||||||
r = obj.fn(1, 2)
|
r = obj.fn(1, 2)
|
||||||
self.assertEqual(r, ["spam", "eggs"])
|
self.assertEqual(r.result, ["spam", "eggs"])
|
||||||
r = obj.fn(1, 3)
|
r = obj.fn(1, 3)
|
||||||
self.assertEqual(r, ["chips"])
|
self.assertEqual(r.result, ["chips"])
|
||||||
obj.mock.assert_not_called()
|
obj.mock.assert_not_called()
|
||||||
|
|
||||||
def test_cache_iterable_with_sync_exception(self):
|
def test_cache_iterable_with_sync_exception(self):
|
||||||
|
|
Loading…
Reference in a new issue