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

Commit

Permalink
When fetching full dict don't return partial
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjohnston committed Jul 20, 2022
1 parent 424796b commit 67abb91
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 28 deletions.
28 changes: 1 addition & 27 deletions synapse/util/caches/dictionary_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,33 +240,7 @@ def _get_full_dict(
assert isinstance(entry, dict)
return DictionaryEntry(True, set(), entry)

# If not, check if we have cached any dict keys at all for this cache
# key.
all_entries = self.cache.get_multi(
(key,),
_Sentinel.sentinel,
)
if all_entries is _Sentinel.sentinel:
return DictionaryEntry(False, set(), {})

# If there are entries we need to unwrap the returned cache nodes
# and `_PerKeyValue` into the `DictionaryEntry`.
values = {}
known_absent = set()
for (_, dict_key), dict_value in all_entries:
# We have explicitly looked for a full cache key, so we
# shouldn't see one.
assert dict_key != _FullCacheKey.KEY

# ... therefore the values must be `_PerKeyValue`
assert isinstance(dict_value, _PerKeyValue)

if dict_value.value is _Sentinel.sentinel:
known_absent.add(dict_key)
else:
values[dict_key] = dict_value.value

return DictionaryEntry(False, known_absent, values)
return DictionaryEntry(False, set(), {})

def invalidate(self, key: KT) -> None:
self.check_thread()
Expand Down
3 changes: 2 additions & 1 deletion tests/util/test_dict_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,12 @@ def test_multi_insert(self):
test_value_2 = {"test2": "test_simple_cache_hit_miss_partial2"}
self.cache.update(seq, key, test_value_2, fetched_keys=set("test2"))

c = self.cache.get(key)
c = self.cache.get(key, dict_keys=["test", "test2"])
self.assertEqual(
{
"test": "test_simple_cache_hit_miss_partial",
"test2": "test_simple_cache_hit_miss_partial2",
},
c.value,
)
self.assertEqual(c.full, False)

0 comments on commit 67abb91

Please sign in to comment.