Allow user to force refresh metadata#5933
Conversation
5c4ea1b to
8ef4c71
Compare
Codecov Report
@@ Coverage Diff @@
## master #5933 +/- ##
===========================================
+ Coverage 63.52% 77.83% +14.31%
===========================================
Files 393 46 -347
Lines 23667 9434 -14233
Branches 2638 0 -2638
===========================================
- Hits 15034 7343 -7691
+ Misses 8620 2091 -6529
+ Partials 13 0 -13
Continue to review full report at Codecov.
|
e589031 to
6191dbd
Compare
14b7eac to
adb42e6
Compare
adb42e6 to
8416ca8
Compare
betodealmeida
left a comment
There was a problem hiding this comment.
Looks great, @youngyjd! I have just a couple comments, and it would be good to preserve the old endpoint.
Also — and this can be done on a separate PR, just curious — how hard would it be to show in the tooltip when the schemas were cached?
|
|
||
| ```bash | ||
| cd superset/assets/javascripts | ||
| cd superset/assets/spec |
There was a problem hiding this comment.
Thank you for fixing this!
| def schemas(self, db_id, force_refresh): | ||
| db_id = int(db_id) | ||
| force_refresh = force_refresh.lower() == 'true' | ||
| print(force_refresh) |
| '#sqlalchemy.schema.MetaData) call.<br/>' | ||
| '2. The ``schemas_allowed_for_csv_upload`` is a comma separated list ' | ||
| '2. The ``metadata_cache_timeout`` is a cache timeout setting ' | ||
| 'in second for metadata fetch of this database. Specify it as ' |
| enable_cache=enable_cache, | ||
| cache_timeout=(self.get_extra(). | ||
| get('metadata_cache_timeout', {}). | ||
| get('schema_cache_timeout')), |
There was a problem hiding this comment.
This is a bit hard to read — at first I thought these were 3 arguments being passed, and get was a function.
Personally I would rewrite this as:
extra = self.get_extra()
try:
cache_timeout = extra['metadata_cache_timeout']['schema_cache_timeout']
except KeyError:
cache_timeout = NoneThere's a proposal that would allow this to be written as:
cache_timeout = self.get_extra()?['metadata_cache_timeout']?['schema_cache_timeout']|
|
||
|
|
||
| def memoized_func(timeout=5 * 60, key=view_cache_key): | ||
| def default_timetout(*unused_args, **unused_kwargs): |
| return True | ||
|
|
||
|
|
||
| def memoized_func(timeout=default_timetout, |
| @expose('/schemas/<db_id>/') | ||
| def schemas(self, db_id): | ||
| @expose('/schemas/<db_id>/<force_refresh>/') | ||
| def schemas(self, db_id, force_refresh): |
There was a problem hiding this comment.
It would be good to preserve the old behavior, just in case something is using the API. I think you can do here:
@expose('/schemas/<db_id>/<force_refresh>/')
@expose('/schemas/<db_id>/')
def schemas(self, db_id, force_refresh=True):And it would handle both cases.
|
Comments addressed. PTAL @betodealmeida |
|
Awesome, thanks! :) |
* Allow user to force refresh metadata * fix javascript test error * nit * fix styling * allow custom cache timeout configuration on any database * minor improvement * nit * fix test * nit * preserve the old endpoint
* Allow user to force refresh metadata * fix javascript test error * nit * fix styling * allow custom cache timeout configuration on any database * minor improvement * nit * fix test * nit * preserve the old endpoint (cherry picked from commit 712c1aa)
* Allow user to force refresh metadata * fix javascript test error * nit * fix styling * allow custom cache timeout configuration on any database * minor improvement * nit * fix test * nit * preserve the old endpoint
Several changes in this PR:
"metadata_cache_timeout": {}setting inextraof a database configuration. Ifschema_cache_timeoutis unset in the field, cache will not be enabled for the metadata fetch of this database. If it is set to 0, cache will never time out.RefreshLabel. It is similar toCacheLabelbut simpler. Not sure if we need to integrate the two labels into one component and not sure how to implement if so. Any suggestion is welcome.Next step:
Implement similar things on fetching table list.