From 0d9c230bd74a94006a6ff9e9e32be7ea8a6b51ac Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Sat, 16 May 2020 19:51:15 -0700 Subject: hack-y global serde ApiClient Motivation is to speed up serialization/deserialization for entity encoding. --- fatcat_scholar/api_entities.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'fatcat_scholar') diff --git a/fatcat_scholar/api_entities.py b/fatcat_scholar/api_entities.py index 53455e8..738c5c8 100644 --- a/fatcat_scholar/api_entities.py +++ b/fatcat_scholar/api_entities.py @@ -3,6 +3,8 @@ import json import collections from fatcat_openapi_client import ApiClient +_global_serde_api_client = ApiClient() + def entity_to_dict(entity, api_client=None): """ Hack to take advantage of the code-generated serialization code. @@ -14,7 +16,7 @@ def entity_to_dict(entity, api_client=None): that this argument may become mandatory. """ if not api_client: - api_client = ApiClient() + api_client = _global_serde_api_client return api_client.sanitize_for_serialization(entity) def entity_from_json(json_str, entity_type, api_client=None): @@ -24,7 +26,7 @@ def entity_from_json(json_str, entity_type, api_client=None): See note on `entity_to_dict()` about api_client argument. """ if not api_client: - api_client = ApiClient() + api_client = _global_serde_api_client thing = collections.namedtuple('Thing', ['data']) thing.data = json_str return api_client.deserialize(thing, entity_type) -- cgit v1.2.3