diff options
| author | Bryan Newbold <bnewbold@robocracy.org> | 2019-01-28 15:32:29 -0800 | 
|---|---|---|
| committer | Bryan Newbold <bnewbold@robocracy.org> | 2019-01-28 15:32:29 -0800 | 
| commit | a0c2548c9ced4caa6ce088fed468059fe86013b8 (patch) | |
| tree | 076630ab66ace703a6d1e8b2d42e03d8823e4a99 /python | |
| parent | 2219d6f04429ea42eb0381c29780f55b44770b87 (diff) | |
| download | fatcat-a0c2548c9ced4caa6ce088fed468059fe86013b8.tar.gz fatcat-a0c2548c9ced4caa6ce088fed468059fe86013b8.zip | |
vastly improve entity_to_dict() speed
Diffstat (limited to 'python')
| -rw-r--r-- | python/fatcat_tools/transforms.py | 10 | 
1 files changed, 9 insertions, 1 deletions
| diff --git a/python/fatcat_tools/transforms.py b/python/fatcat_tools/transforms.py index 37cbf1d2..9cb557ad 100644 --- a/python/fatcat_tools/transforms.py +++ b/python/fatcat_tools/transforms.py @@ -5,7 +5,13 @@ from fatcat_client import ApiClient  def entity_to_dict(entity, api_client=None):      """ -    Hack to take advantage of the code-generated serialization code +    Hack to take advantage of the code-generated serialization code. + +    Initializing/destroying ApiClient objects is surprisingly expensive +    (because it involves a threadpool), so we allow passing an existing +    instance. If you already have a full-on API connection `api`, you can +    access the ApiClient object as `api.api_client`. This is such a speed-up +    that this argument may become mandatory.      """      if not api_client:          api_client = ApiClient() @@ -14,6 +20,8 @@ def entity_to_dict(entity, api_client=None):  def entity_from_json(json_str, entity_type, api_client=None):      """      Hack to take advantage of the code-generated deserialization code + +    See not on `entity_to_dict()` about api_client argument.      """      if not api_client:          api_client = ApiClient() | 
