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

Implemented cached version of generate_oas_component() #972

Merged
merged 2 commits into from
Jan 22, 2024

Conversation

Bartvaderkin
Copy link
Contributor

I tried this after-hours and it works surprisingly well so I cleaned it up and put it here:

It caches generate_oas_component() calls that are repeated multiple times, like when they are part of a TestCase.setup() or some other often re-used code like the MockAPIData class.

It works by using some funky python hash() code to get a cache key and deepcopy() to isolate each usage.

Also it's obviously a memory hole, but memory and deepcopy() are a lot cheaper then CPU cycles running the OAS/faker stack.

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (443973e) 94.80% compared to head (6d608cb) 94.80%.
Report is 7 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #972      +/-   ##
===========================================
- Coverage    94.80%   94.80%   -0.01%     
===========================================
  Files          857      858       +1     
  Lines        30068    30133      +65     
===========================================
+ Hits         28507    28567      +60     
- Misses        1561     1566       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Bartvaderkin Bartvaderkin marked this pull request as ready for review January 19, 2024 10:42
Copy link
Contributor

@stevenbal stevenbal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good 👍. Does it make the tests faster as well?

@alextreme alextreme merged commit d1c3777 into develop Jan 22, 2024
14 checks passed
@alextreme alextreme deleted the fix/generate_oas_comp_cache branch January 22, 2024 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants