-
Notifications
You must be signed in to change notification settings - Fork 14k
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
fix: memoize primitives #19930
fix: memoize primitives #19930
Conversation
742bf57
to
a7ce679
Compare
Codecov Report
@@ Coverage Diff @@
## master #19930 +/- ##
==========================================
- Coverage 66.53% 66.51% -0.03%
==========================================
Files 1715 1715
Lines 65060 65060
Branches 6723 6723
==========================================
- Hits 43289 43274 -15
- Misses 20060 20075 +15
Partials 1711 1711
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
In the example above the result for `1+2` will be stored under the key of name "1+2", | ||
in the `cache_manager.data_cache` cache. | ||
|
||
Note: this decorator should be used only with functions that return primitives, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yey!
(cherry picked from commit 1ebdaac)
🏷️ preset:2022.17 |
schema=schema, | ||
force=True, | ||
cache=database.table_cache_enabled, | ||
cache_timeout=database.table_cache_timeout, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@beto what would happen if this value returns from cache prior to this change and it's not a list of strings but rather the DatasourceName object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great question, the cool thing about this solution is that it still works with old cached values:
>>> from typing import NamedTuple
>>>
>>> class DatasourceName(NamedTuple):
... table: str
... schema: str
...
>>> a = DatasourceName(table='t', schema='s')
>>> DatasourceName(*a)
DaasourceName(table='t', schema='s')
SUMMARY
In some of the views we're caching
DatasourceName
namedtuples to Redis using thememoized_func
decorator. We found that in certain cases the object that comes back from the cache is a list of[table, schema]
, instead ofDatasourceName(table=table, schema=schema)
, which breaks the view.I changed the code in
models/core.py
so that the return value from the memoized functions is a primitive (a tuple of(table, schema)
), and we rebuild the namedtuple inviews/core.py
, to prevent this bug from happening.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A
TESTING INSTRUCTIONS
Updated unit tests.
ADDITIONAL INFORMATION