-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: lru_cache issues + meta info missing
Context: codecov/engineering-team#119 So the real issue with the meta info is fixed in codecov/shared#22. spoiler: reusing the report details cached values and _changing_ them is not a good idea. However in the process of debuging that @matt-codecov pointed out that we were not using lru_cache correctly. Check this very well made video: https://www.youtube.com/watch?v=sVjtp6tGo0g So the present changes upgrade shared so we fix the meta info stuff AND address the cache issue. There are further complications with the caching situation, which explain why I decided to add the cached value in the `obj` instead of `self`. The thing is that there's only 1 instance of `ArchiveField` shared among ALL instances of the model class (for example, all `ReportDetail` instances). This kinda makes sense because we only create an instance of `ArchiveField` in the declaration of the `ReportDetail` class. Because of that if the cache is in the `self` of `ArchiveField` different instances of `ReportDetails` will have dirty cached value of other `ReportDetails` instances and we get wrong values. To fix that I envision 3 possibilities: 1. Putting the cached value in the `ReportDetails` instance directly (the `obj`), and checking for the presence of that value. If it's there it's guaranteed that we put it there, and we can update it on writes, so that we can always use it. Because it is for each `ReportDetails` instance we always get the correct value, and it's cleared when the instance is killed and garbage collected. 2. Storing an entire table of cached values in the `self` (`ArchiveField`) and using the appropriate cache value when possible. The problem here is that we need to manage the cache ourselves (which is not that hard, honestly) and probably set a max value. Then we will populate the cache and over time evict old values. The 2nd problem is that the values themselves might be too big to hold in memory (which can be fixed by setting a very small value in the cache size). There's a fine line there, but it's more work than option 1 anyway. 3. We move the getting and parsing of the value to outside `ArchiveField` (so it's a normal function) and use `lru_cache` in that function. Because the `rehydrate` function takes a reference to `obj` I don't think we should pass that, so the issue here is that we can't cache the rehydrated value, and would have to rehydrate every time (which currently is not expensive at all in any model) This is an instance cache, so it shouldn't need to be cleaned for the duration of the instance's life (because it is updates on the SET) closes codecov/engineering-team#119
- Loading branch information
1 parent
3bbd3c4
commit 4bacedc
Showing
6 changed files
with
22 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ factory-boy | |
fakeredis | ||
freezegun | ||
git+ssh://[email protected]/codecov/[email protected]#egg=codecovopentelem | ||
git+ssh://[email protected]/codecov/shared.git@8573d97fd99470b73bbff6bdb69c54177e0de409#egg=shared | ||
git+ssh://[email protected]/codecov/shared.git@6a8a33248804a9c101d34f417efda7c11e4bbe63#egg=shared | ||
gunicorn | ||
https://github.com/photocrowd/django-cursor-pagination/archive/f560902696b0c8509e4d95c10ba0d62700181d84.tar.gz | ||
minio | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -325,7 +325,7 @@ sentry-sdk==1.19.1 | |
# via -r requirements.in | ||
setproctitle==1.1.10 | ||
# via -r requirements.in | ||
shared @ git+ssh://[email protected]/codecov/shared.git@8573d97fd99470b73bbff6bdb69c54177e0de409 | ||
shared @ git+ssh://[email protected]/codecov/shared.git@6a8a33248804a9c101d34f417efda7c11e4bbe63 | ||
# via -r requirements.in | ||
simplejson==3.17.2 | ||
# via -r requirements.in | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters