From 56000394c4746246efd1a2846310f993c53eda8a Mon Sep 17 00:00:00 2001 From: Jonathan Kim Date: Sun, 1 Jul 2018 11:32:16 +0100 Subject: [PATCH] Simplify code --- graphene/utils/deduplicator.py | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/graphene/utils/deduplicator.py b/graphene/utils/deduplicator.py index e381c0dd..fd5682b1 100644 --- a/graphene/utils/deduplicator.py +++ b/graphene/utils/deduplicator.py @@ -1,8 +1,4 @@ -from collections import defaultdict, Mapping, OrderedDict - - -def nested_dict(): - return defaultdict(nested_dict) +from collections import Mapping, OrderedDict def deflate(node, index=None, path=None): @@ -13,24 +9,15 @@ def deflate(node, index=None, path=None): if node and 'id' in node and '__typename' in node: route = ','.join(path) + cache_key = ':'.join([route, str(node['__typename']), str(node['id'])]) - if ( - route in index and - node['__typename'] in index[route] and - index[route][node['__typename']].get(node['id']) - ): + if index.get(cache_key) is True: return { '__typename': node['__typename'], 'id': node['id'], } else: - if route not in index: - index[route] = {} - - if node['__typename'] not in index[route]: - index[route][node['__typename']] = {} - - index[route][node['__typename']][node['id']] = True + index[cache_key] = True field_names = node.keys() result = OrderedDict()