Skip to content

Commit 5600039

Browse files
committed
Simplify code
1 parent cbcaac6 commit 5600039

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

graphene/utils/deduplicator.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
from collections import defaultdict, Mapping, OrderedDict
2-
3-
4-
def nested_dict():
5-
return defaultdict(nested_dict)
1+
from collections import Mapping, OrderedDict
62

73

84
def deflate(node, index=None, path=None):
@@ -13,24 +9,15 @@ def deflate(node, index=None, path=None):
139

1410
if node and 'id' in node and '__typename' in node:
1511
route = ','.join(path)
12+
cache_key = ':'.join([route, str(node['__typename']), str(node['id'])])
1613

17-
if (
18-
route in index and
19-
node['__typename'] in index[route] and
20-
index[route][node['__typename']].get(node['id'])
21-
):
14+
if index.get(cache_key) is True:
2215
return {
2316
'__typename': node['__typename'],
2417
'id': node['id'],
2518
}
2619
else:
27-
if route not in index:
28-
index[route] = {}
29-
30-
if node['__typename'] not in index[route]:
31-
index[route][node['__typename']] = {}
32-
33-
index[route][node['__typename']][node['id']] = True
20+
index[cache_key] = True
3421

3522
field_names = node.keys()
3623
result = OrderedDict()

0 commit comments

Comments
 (0)