Skip to content

Commit 9b9e538

Browse files
SG-38119 Release v3.8.0. Make payload optimization default (#366)
* Make payload optimization default * Packaging for v3.8.0 * Update HISTORY.rst Co-authored-by: Julien Langlois <16244608+julien-lang@users.noreply.github.com> --------- Co-authored-by: Julien Langlois <16244608+julien-lang@users.noreply.github.com>
1 parent b83b9e2 commit 9b9e538

5 files changed

Lines changed: 31 additions & 20 deletions

File tree

HISTORY.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,17 @@ Flow Production Tracking Python API Changelog
44

55
Here you can see the full list of changes between each Python API release.
66

7+
v3.8.0 (2024 Feb 7)
8+
===================
9+
10+
- Extend the payload optimizations to the ``in`` and ``not_in`` filters and
11+
the ``update`` method.
12+
- The payload optimization is now enabled by default.
13+
It can be disabled with the ``SHOTGUN_API_DISABLE_ENTITY_OPTIMIZATION``
14+
environment variable.
15+
716
v3.7.0 (2024 Dec 9)
8-
===========================
17+
===================
918
- Remove unnecessary data in the payload when combining related queries before sending it to the server.
1019
This would improve overall performance decreasing network latency and server processing.
1120
See documentation for more information.

docs/reference.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -950,13 +950,13 @@ Stores the number of milliseconds to wait between request retries. By default,
950950
In the case that both this environment variable and the config's ``rpc_attempt_interval`` property are set, the value in ``rpc_attempt_interal`` will be used.
951951

952952

953-
SHOTGUN_API_ENABLE_ENTITY_OPTIMIZATION
953+
SHOTGUN_API_DISABLE_ENTITY_OPTIMIZATION
954954
=======================================
955955

956956
.. note:: (v3.7.0) This is an experimental feature. Feel free to disable this feature if you are experiencing any issues.
957957

958-
When set to ``1``, this environment variable will enable the entity optimization feature.
959-
This feature is disabled by default and is used to reduce the payload size made to the server when retrieving entities
958+
When set to ``1``, this environment variable will disable the entity optimization feature.
959+
This feature is enabled by default and is used to reduce the payload size made to the server when retrieving entities
960960
improving overall performance by decreasing network latency and server processing.
961961

962962
For example, a ``find`` call like this:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
setup(
2222
name='shotgun_api3',
23-
version='3.7.0',
23+
version='3.8.0',
2424
description='Flow Production Tracking Python API',
2525
long_description=readme,
2626
author='Autodesk',

shotgun_api3/shotgun.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def _is_mimetypes_broken():
105105

106106
SG_TIMEZONE = SgTimezone()
107107

108-
SHOTGUN_API_ENABLE_ENTITY_OPTIMIZATION = False
108+
SHOTGUN_API_DISABLE_ENTITY_OPTIMIZATION = False
109109

110110
NO_SSL_VALIDATION = False
111111
"""
@@ -118,7 +118,7 @@ def _is_mimetypes_broken():
118118

119119
# ----------------------------------------------------------------------------
120120
# Version
121-
__version__ = "3.7.0"
121+
__version__ = "3.8.0"
122122

123123
# ----------------------------------------------------------------------------
124124
# Errors
@@ -652,9 +652,9 @@ def __init__(self,
652652
raise ValueError("Value of SHOTGUN_API_RETRY_INTERVAL must be positive, "
653653
"got '%s'." % self.config.rpc_attempt_interval)
654654

655-
global SHOTGUN_API_ENABLE_ENTITY_OPTIMIZATION
656-
if os.environ.get("SHOTGUN_API_ENABLE_ENTITY_OPTIMIZATION", "0").strip().lower() == "1":
657-
SHOTGUN_API_ENABLE_ENTITY_OPTIMIZATION = True
655+
global SHOTGUN_API_DISABLE_ENTITY_OPTIMIZATION
656+
if os.environ.get("SHOTGUN_API_DISABLE_ENTITY_OPTIMIZATION", "0").strip().lower() == "1":
657+
SHOTGUN_API_DISABLE_ENTITY_OPTIMIZATION = True
658658

659659
self._connection = None
660660

@@ -1136,12 +1136,12 @@ def _add_project_param(self, params, project_entity):
11361136
def _translate_update_params(
11371137
self, entity_type, entity_id, data, multi_entity_update_modes
11381138
):
1139-
global SHOTGUN_API_ENABLE_ENTITY_OPTIMIZATION
1139+
global SHOTGUN_API_DISABLE_ENTITY_OPTIMIZATION
11401140

11411141
def optimize_field(field_dict):
1142-
if SHOTGUN_API_ENABLE_ENTITY_OPTIMIZATION:
1143-
return {k: _get_type_and_id_from_value(v) for k, v in field_dict.items()}
1144-
return field_dict
1142+
if SHOTGUN_API_DISABLE_ENTITY_OPTIMIZATION:
1143+
return field_dict
1144+
return {k: _get_type_and_id_from_value(v) for k, v in field_dict.items()}
11451145

11461146
full_fields = self._dict_to_list(
11471147
data,
@@ -4493,9 +4493,9 @@ def _translate_filters_simple(sg_filter):
44934493

44944494
# Payload optimization: Do not send a full object
44954495
# just send the `type` and `id` when combining related queries
4496-
global SHOTGUN_API_ENABLE_ENTITY_OPTIMIZATION
4496+
global SHOTGUN_API_DISABLE_ENTITY_OPTIMIZATION
44974497
if (
4498-
SHOTGUN_API_ENABLE_ENTITY_OPTIMIZATION
4498+
not SHOTGUN_API_DISABLE_ENTITY_OPTIMIZATION
44994499
and condition["path"] != "id"
45004500
and condition["relation"] in ["is", "is_not", "in", "not_in"]
45014501
and isinstance(values[0], dict)

tests/test_unit.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ def test_invalid(self):
408408

409409
self.assertRaises(api.ShotgunError, api.shotgun._translate_filters, filters, "all")
410410

411+
@mock.patch.dict(os.environ, {"SHOTGUN_API_DISABLE_ENTITY_OPTIMIZATION": "1"})
411412
def test_related_object(self):
412413
filters = [
413414
[
@@ -434,10 +435,11 @@ def test_related_object(self):
434435
}
435436
],
436437
}
438+
api.Shotgun("http://server_path", "script_name", "api_key", connect=False)
437439
result = api.shotgun._translate_filters(filters, "all")
438440
self.assertEqual(result, expected)
439441

440-
@mock.patch.dict(os.environ, {"SHOTGUN_API_ENABLE_ENTITY_OPTIMIZATION": "1"})
442+
@mock.patch("shotgun_api3.shotgun.SHOTGUN_API_DISABLE_ENTITY_OPTIMIZATION", False)
441443
def test_related_object_entity_optimization_is(self):
442444
filters = [
443445
[
@@ -487,7 +489,7 @@ def test_related_object_entity_optimization_is(self):
487489
result = api.shotgun._translate_filters(filters, "all")
488490
self.assertEqual(result, expected)
489491

490-
@mock.patch.dict(os.environ, {"SHOTGUN_API_ENABLE_ENTITY_OPTIMIZATION": "1"})
492+
@mock.patch("shotgun_api3.shotgun.SHOTGUN_API_DISABLE_ENTITY_OPTIMIZATION", False)
491493
def test_related_object_entity_optimization_in(self):
492494
filters = [
493495
[
@@ -561,7 +563,7 @@ def test_related_object_update_entity(self):
561563
result = sg._translate_update_params(entity_type, entity_id, data, multi_entity_update_modes)
562564
self.assertEqual(result, expected)
563565

564-
@mock.patch.dict(os.environ, {"SHOTGUN_API_ENABLE_ENTITY_OPTIMIZATION": "1"})
566+
@mock.patch("shotgun_api3.shotgun.SHOTGUN_API_DISABLE_ENTITY_OPTIMIZATION", False)
565567
def test_related_object_update_optimization_entity(self):
566568
entity_type = "Anything"
567569
entity_id = 999
@@ -612,7 +614,7 @@ def test_related_object_update_optimization_entity(self):
612614
result = sg._translate_update_params(entity_type, entity_id, data, multi_entity_update_modes)
613615
self.assertEqual(result, expected)
614616

615-
@mock.patch.dict(os.environ, {"SHOTGUN_API_ENABLE_ENTITY_OPTIMIZATION": "1"})
617+
@mock.patch("shotgun_api3.shotgun.SHOTGUN_API_DISABLE_ENTITY_OPTIMIZATION", False)
616618
def test_related_object_update_optimization_entity_multi(self):
617619
entity_type = "Asset"
618620
entity_id = 6626

0 commit comments

Comments
 (0)