diff options
author | Bryan Newbold <bnewbold@archive.org> | 2020-05-16 19:51:15 -0700 |
---|---|---|
committer | Bryan Newbold <bnewbold@archive.org> | 2020-05-16 19:51:17 -0700 |
commit | 0d9c230bd74a94006a6ff9e9e32be7ea8a6b51ac (patch) | |
tree | 05b635a504fa0fdf40da3805f3ac9f3f9437b3e1 /fatcat_scholar/api_entities.py | |
parent | f1f7842dd2ed110e9958f56d79ec504ae5d2bcd6 (diff) | |
download | fatcat-scholar-0d9c230bd74a94006a6ff9e9e32be7ea8a6b51ac.tar.gz fatcat-scholar-0d9c230bd74a94006a6ff9e9e32be7ea8a6b51ac.zip |
hack-y global serde ApiClient
Motivation is to speed up serialization/deserialization for entity
encoding.
Diffstat (limited to 'fatcat_scholar/api_entities.py')
-rw-r--r-- | fatcat_scholar/api_entities.py | 6 |
1 files changed, 4 insertions, 2 deletions
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) |