Skip to content

Commit 4067a98

Browse files
committed
profile-retrieval is still a little slow, so speed up json parsing
Jira: IAM-1668
1 parent 00c2232 commit 4067a98

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

python-modules/cis_profile_retrieval_service/cis_profile_retrieval_service/advanced.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""Support advanced search queries for inclusion in routes via DynamoDb."""
2-
import json
2+
import orjson
33
import logging
44
from flask_restful import Resource
55
from flask_restful import reqparse
@@ -55,7 +55,7 @@ def filter_full_profiles(scopes, filter_display, vault_profiles):
5555
v2_profiles = []
5656
for profile in vault_profiles:
5757
if isinstance(profile.get("profile"), str):
58-
vault_profile = json.loads(profile.get("profile"))
58+
vault_profile = orjson.loads(profile.get("profile"))
5959
else:
6060
vault_profile = profile.get("profile")
6161

python-modules/cis_profile_retrieval_service/cis_profile_retrieval_service/common.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import boto3
22
import botocore
3-
import json
3+
import orjson
44
import logging
55
import os
66
import re
77
from botocore.stub import Stubber
88
from everett.ext.inifile import ConfigIniEnv
99
from everett.manager import ConfigManager
1010
from everett.manager import ConfigOSEnv
11-
from json import dumps
1211
from cis_profile.fake_profile import batch_create_fake_profiles
1312
from cis_identity_vault.models import user
1413
from cis_identity_vault.vault import IdentityVault
@@ -96,7 +95,7 @@ def seed(number_of_fake_users=100):
9695
"user_uuid": identity.get("uuid").get("value"),
9796
"primary_username": identity.get("primary_username").get("value"),
9897
"sequence_number": "1234567890",
99-
"profile": dumps(identity),
98+
"profile": orjson.dumps(identity),
10099
}
101100

102101
user_profile.create(identity_vault_data_structure)
@@ -112,7 +111,7 @@ def seed(number_of_fake_users=100):
112111
"user_uuid": identity.get("uuid").get("value"),
113112
"primary_username": identity.get("primary_username").get("value"),
114113
"sequence_number": "1234567890",
115-
"profile": dumps(identity),
114+
"profile": orjson.dumps(identity),
116115
}
117116
user_profile.create(identity_vault_data_structure)
118117
logger.info("Count: {} seed users created.".format(number_of_fake_users))
@@ -126,7 +125,7 @@ def load_dirty_json(dirty_json):
126125
]
127126
for r, s in regex_replace:
128127
dirty_json = re.sub(r, s, dirty_json)
129-
clean_json = json.loads(dirty_json)
128+
clean_json = orjson.loads(dirty_json)
130129
return clean_json
131130

132131

python-modules/cis_profile_retrieval_service/cis_profile_retrieval_service/v2_api.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import json
1+
import orjson
22

33
from aws_xray_sdk.ext.flask.middleware import XRayMiddleware
44
from aws_xray_sdk.core import xray_recorder
@@ -98,7 +98,7 @@ def get(self, primary_email):
9898
if len(result["Items"]) > 0:
9999
vault_profile = result["Items"][0]["profile"]
100100
exists_in_cis = True
101-
exists_in_ldap = User(user_structure_json=json.loads(vault_profile)) \
101+
exists_in_ldap = User(user_structure_json=orjson.loads(vault_profile)) \
102102
.as_dict()["access_information"]["ldap"]["values"] is not None
103103

104104
return jsonify({
@@ -236,7 +236,7 @@ def getUser(id, find_by):
236236

237237
if len(result["Items"]) > 0:
238238
vault_profile = result["Items"][0]["profile"]
239-
v2_profile = User(user_structure_json=json.loads(vault_profile))
239+
v2_profile = User(user_structure_json=orjson.loads(vault_profile))
240240

241241
if v2_profile.active.value == active or active is None:
242242
if "read:fullprofile" in scopes:
@@ -318,7 +318,7 @@ def get(self):
318318
active = True # Support returning only active users by default.
319319

320320
for profile in result.get("Items"):
321-
vault_profile = json.loads(profile.get("profile"))
321+
vault_profile = orjson.loads(profile.get("profile"))
322322
v2_profile = User(user_structure_json=vault_profile)
323323

324324
# This must be a pre filtering check because mutation is real.

requirements/core.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ importlib_metadata==2.0.0
3030
itsdangerous==1.1.0
3131
Jinja2==2.11.2
3232
jmespath==0.10.0
33+
orjson==3.11.0
3334
jsonpickle==1.4.1
3435
jsonschema==3.2.0
3536
MarkupSafe==1.1.1

0 commit comments

Comments
 (0)