-
-
Notifications
You must be signed in to change notification settings - Fork 27
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
Update cache id when object changes #72
Conversation
How do we generate the same uuid for the same object each time? I think this essentially will disable the cache. |
Sorry - I got carried away thinking I had a fix..! Yes this bypasses the cache completely. |
Hmm. I forget exactly how this code is working, but perhaps we only need to remember the result when it's a JsonRef object. In that case possibly the |
@gazpachoking I've tried a few approaches but still sometimes get inconsistent outputs. I thought updating the id when the object changes might help, but when running multiple pytest cases there were failures. It can be hard to recreate as adding a print statement can make tests pass successfully. I did try without any caching with a simple timeit function and there was very little difference. I'm not sure if that would just be for my specific use case (loading https://github.com/geographika/mappyfile/blob/master/mappyfile/schemas/map.json). """
1000 loops
With cache:
0.002243063199974131 (each run)
2.243063199974131 (total time)
Without cache:
0.0023388927999767476
2.3388927999767475
"""
import timeit
N = 1000
t = timeit.timeit(
stmt="json.dumps(validator.get_versioned_schema(8.2, 'map'))",
setup="from mappyfile.validator import Validator; import json; validator = Validator()",
number=N,
) |
The cache isn't actually to speed things up, it's to prevent infinite recursion. If there is a recursive structure created by a json reference, we need to create the recursive structure in python, rather than recurse infinitely. |
@gazpachoking the latest changes fix my issues, and pass the test suite ( |
Fixed with e827f23 - closing this. |
Fix for #61 and #71. Uses the
uuid
to ensure unique keys are used in the_walk_refs
_processed
dictionary.