Skip to content

Commit

Permalink
perf: use prettyPrint=false by default (#28)
Browse files Browse the repository at this point in the history
This tells One Platform APIs not to use excessive whitespace in
responses. For some reason, the backend defaults to prettyPrint=true and
does not provide a mechanism for overriding this.

In response to internal customer issue 168522192.

Tested locally against `google-cloud-bigquery` system and sample tests.

Co-authored-by: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com>
  • Loading branch information
tswast and busunkim96 committed Sep 21, 2020
1 parent 2bdc50e commit c407b5d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
8 changes: 6 additions & 2 deletions google/cloud/_http.py
Expand Up @@ -211,8 +211,12 @@ def build_api_url(
)

query_params = query_params or {}
if query_params:
url += "?" + urlencode(query_params, doseq=True)

if "prettyPrint" not in query_params:
query_params = query_params.copy()
query_params["prettyPrint"] = "false"

url += "?" + urlencode(query_params, doseq=True)

return url

Expand Down
13 changes: 10 additions & 3 deletions tests/unit/test__http.py
Expand Up @@ -184,9 +184,16 @@ def test_build_api_url_no_extra_query_params(self):
client = object()
conn = self._make_mock_one(client)
# Intended to emulate self.mock_template
URI = "/".join([conn.API_BASE_URL, "mock", conn.API_VERSION, "foo"])
URI = "/".join([conn.API_BASE_URL, "mock", conn.API_VERSION, "foo?prettyPrint=false"])
self.assertEqual(conn.build_api_url("/foo"), URI)

def test_build_api_url_w_pretty_print_query_params(self):
client = object()
conn = self._make_mock_one(client)
uri = conn.build_api_url("/foo", {"prettyPrint": "true"})
URI = "/".join([conn.API_BASE_URL, "mock", conn.API_VERSION, "foo?prettyPrint=true"])
self.assertEqual(uri, URI)

def test_build_api_url_w_extra_query_params(self):
from six.moves.urllib.parse import parse_qs
from six.moves.urllib.parse import urlsplit
Expand Down Expand Up @@ -319,7 +326,7 @@ def test_api_request_defaults(self):
"User-Agent": conn.user_agent,
CLIENT_INFO_HEADER: conn.user_agent,
}
expected_url = "{base}/mock/{version}{path}".format(
expected_url = "{base}/mock/{version}{path}?prettyPrint=false".format(
base=conn.API_BASE_URL, version=conn.API_VERSION, path=path
)
http.request.assert_called_once_with(
Expand Down Expand Up @@ -481,7 +488,7 @@ def test_api_request_w_timeout(self):
"User-Agent": conn.user_agent,
CLIENT_INFO_HEADER: conn.user_agent,
}
expected_url = "{base}/mock/{version}{path}".format(
expected_url = "{base}/mock/{version}{path}?prettyPrint=false".format(
base=conn.API_BASE_URL, version=conn.API_VERSION, path=path
)
http.request.assert_called_once_with(
Expand Down

0 comments on commit c407b5d

Please sign in to comment.