diff options
author | Erik Johnston <erikj@jki.re> | 2017-01-17 11:51:09 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-17 11:51:09 +0000 |
commit | d11d7cdf875e524ce217ff3b091a07fb1c3b99ae (patch) | |
tree | 5f88266e2cc5c5ea5afe564d4488f65af3d227d1 /synapse/util/caches/treecache.py | |
parent | Merge pull request #1810 from matrix-org/erikj/state_auth_splitout_split (diff) | |
parent | Tidy up test (diff) | |
download | synapse-d11d7cdf875e524ce217ff3b091a07fb1c3b99ae.tar.xz |
Merge pull request #1815 from matrix-org/erikj/iter_cache_size
Optionally measure size of cache by sum of length of values
Diffstat (limited to 'synapse/util/caches/treecache.py')
-rw-r--r-- | synapse/util/caches/treecache.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/synapse/util/caches/treecache.py b/synapse/util/caches/treecache.py index c31585aea3..fcc341a6b7 100644 --- a/synapse/util/caches/treecache.py +++ b/synapse/util/caches/treecache.py @@ -65,12 +65,27 @@ class TreeCache(object): return popped def values(self): - return [e.value for e in self.root.values()] + return list(iterate_tree_cache_entry(self.root)) def __len__(self): return self.size +def iterate_tree_cache_entry(d): + """Helper function to iterate over the leaves of a tree, i.e. a dict of that + can contain dicts. + """ + if isinstance(d, dict): + for value_d in d.itervalues(): + for value in iterate_tree_cache_entry(value_d): + yield value + else: + if isinstance(d, _Entry): + yield d.value + else: + yield d + + class _Entry(object): __slots__ = ["value"] |