Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use orjson for our json renderer #11675

Merged
merged 1 commit into from
Jun 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements/main.in
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ kombu[sqs]~=5.2.4 # https://github.com/celery/celery/issues/7070
mistune
msgpack
natsort
orjson
packaging>=15.2
paginate>=0.5.2
paginate_sqlalchemy
Expand Down
39 changes: 39 additions & 0 deletions requirements/main.txt
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,45 @@ natsort==8.1.0 \
--hash=sha256:c7c1f3f27c375719a4dfcab353909fe39f26c2032a062a8c80cc844eaaca0445 \
--hash=sha256:f59988d2f24e77b6b56f8a8f882d5df6b3b637e09e075abc67b486d59fba1a4b
# via -r requirements/main.in
orjson==3.7.3 \
--hash=sha256:0a4d747a43c5c9240968f74737da9f9978840f9b5c86bb578919c4e1adb05142 \
--hash=sha256:1594555a73670837a94a42ec21470d30a5cbe430bf1683f491b1f87270aaa305 \
--hash=sha256:1b8391a4fb5783fc8cd96f9594d64524204569dec612689e64cabfb6075bffe1 \
--hash=sha256:1cd9cd9bb9cee39aca4f7e1079cc3e180ffad0b13342ac3fabf5ff3caf7285bb \
--hash=sha256:2cc17eb506613dda54061d956c416720dcd660ef6291ff94a88dcbb857933b2d \
--hash=sha256:2efd7561e3a25bf381ee6410c4ca26f3425948074d394fae708bc1b7d2c09100 \
--hash=sha256:320c0ffe508a12e83631e8172c29f42af6ba52473f1c6afec0bc99831d3e7cd9 \
--hash=sha256:38cb1191aae1f62665750f2457d04a8d7b1d289745b1ff3617f665f24cbab3e7 \
--hash=sha256:4205c32a003c732b4fa9c040cd5a0660d87d38a7a97eb8db559d0b22f66bade6 \
--hash=sha256:4cb6ea393398e5665fd84f4bff11fff79fe42c40cc4b38afd8241b15aa72e2c3 \
--hash=sha256:4d10459578c139f428adedff41a78afde7034e277979cbb67b2d0584ddaff320 \
--hash=sha256:5738ab3283e75953b2aba549ebe7061cb883b2fd2d281097009242b3936c0114 \
--hash=sha256:6998ff27b9b9aaa4906f6ad40c6c973339c772143f56e8e920f4843fd6c04e75 \
--hash=sha256:6c59aec36cb77634dd218789bffa801f265a9522cf6311573ae4202a6888abca \
--hash=sha256:6c7eca150d9d7dedf405d82c346105d6475e57789f3c3b4e0d12d59def94cb30 \
--hash=sha256:6ca694b989da69d31f129992bc00310b704adcbde8b3a24b571d883d2783a8e1 \
--hash=sha256:716c8f7eb39128067355bd1bc5e66156934d70295f5c62786a89af9c3f50c4d7 \
--hash=sha256:7406f8d163e7e7f358b34016e828f6b5ce15e6f7f0de3f82089a26ba1b41d75e \
--hash=sha256:7592bc8c2009a7ee39ec1a022bb711f23bf74b9c49ffbe93479cdac16842b5ca \
--hash=sha256:837bcaefb9ba61d40587d25052e3c74652e853108af6e2bc172c001b5f2ffd3e \
--hash=sha256:863b7f13d1fd05b65ba4926f017b0d301d6b898db4ebcb19609af111f77a803c \
--hash=sha256:8ef7696c3771dd11df5a45922794ad17b0421bfb5ba07832b960b653225ca739 \
--hash=sha256:940184f159f6be00e2f4320fdeebe6b842228db26db679c7cad5654818643938 \
--hash=sha256:95fd418e3e93305b728e056fa35096b70261b63ba6df404a8f6af5694b27de20 \
--hash=sha256:99b9c2ed45c06c77a990cd5d37bf43ac815fcb5cc36a2351629d270673ea4b94 \
--hash=sha256:9e68c01d576aaf3d83b3a18a3d2139d2cbfebc415264d7054d37d7fd8292bd08 \
--hash=sha256:9f2248d54957a63cf861285ea46f89ae79853e84ee26593560e8d53892a6b652 \
--hash=sha256:a4eb1ea1afe6494af75e61bf8bbca251e8e4883f1c235652e509e86e0eaf23b6 \
--hash=sha256:a9895be514b3aad76f81c739b7348c31f913971923ac71e0a35443abe6696a6d \
--hash=sha256:a9d68a29111d9e2e9ac45eb339ae4083a754fc9deba3270ef573c87c64e75e3b \
--hash=sha256:ade22b22f2d4baafcdcac63a66893250b51e7601e16f2c93bab29b30d233c5ac \
--hash=sha256:ae229eef7a5a418011627b283d7fe0316d05fef65e88ae6623eecd5c6c701726 \
--hash=sha256:b2dadb4c0e2c4aa81f5bf20d58bd3b742e55c1142dd2bde5707749e77e3a9ad1 \
--hash=sha256:b500e4b1a6e8d93e226c55848419146365b57000f0afb1766475cb0a5b913aac \
--hash=sha256:c06d6162694a83ba2f3a5fdceca9f8a7b30cae78e6e9651c8bdfb33cae3b95a3 \
--hash=sha256:c70e650324ce3efd65c9452c3e59c40f41e28a16a84ed4a56cb4ed84b4d788db \
--hash=sha256:e17adc831c2a909a31b732e59973b6162d969f2e742a7c2428e62cc5fd65e00e
# via -r requirements/main.in
packaging==21.3 \
--hash=sha256:dd47c42927d89ab911e606518907cc2d3a1f38bbd026385970643f9c5b8ecfeb \
--hash=sha256:ef103e05f519cdc783ae24ea4e2e0f508a9c99b2d4969652eed6a2e1ea5bd522
Expand Down
6 changes: 5 additions & 1 deletion tests/unit/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from unittest import mock

import orjson
import pretend
import pytest

Expand Down Expand Up @@ -443,7 +444,10 @@ def __init__(self):
]

assert json_renderer_cls.calls == [
pretend.call(sort_keys=True, separators=(",", ":"))
pretend.call(
serializer=orjson.dumps,
option=orjson.OPT_SORT_KEYS | orjson.OPT_APPEND_NEWLINE,
)
]

assert xmlrpc_renderer_cls.calls == [pretend.call(allow_none=True)]
Expand Down
9 changes: 8 additions & 1 deletion warehouse/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import os
import shlex

import orjson
import transaction

from pyramid import renderers
Expand Down Expand Up @@ -451,7 +452,13 @@ def configure(settings=None):

# We want to configure our JSON renderer to sort the keys, and also to use
# an ultra compact serialization format.
config.add_renderer("json", renderers.JSON(sort_keys=True, separators=(",", ":")))
config.add_renderer(
"json",
renderers.JSON(
serializer=orjson.dumps,
option=orjson.OPT_SORT_KEYS | orjson.OPT_APPEND_NEWLINE,
),
)

# Configure retry support.
config.add_settings({"retry.attempts": 3})
Expand Down