-
Notifications
You must be signed in to change notification settings - Fork 13.8k
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
Allow user to force refresh metadata #5933
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
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.
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?
@@ -332,7 +332,7 @@ commands are invoked. | |||
We use [Mocha](https://mochajs.org/), [Chai](http://chaijs.com/) and [Enzyme](http://airbnb.io/enzyme/) to test Javascript. Tests can be run with: | |||
|
|||
```bash | |||
cd superset/assets/javascripts | |||
cd superset/assets/spec |
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.
Thank you for fixing this!
superset/views/core.py
Outdated
db_id = int(db_id) | ||
force_refresh = force_refresh.lower() == 'true' | ||
print(force_refresh) |
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.
dd
superset/views/core.py
Outdated
@@ -211,7 +211,12 @@ class DatabaseView(SupersetModelView, DeleteMixin, YamlExportMixin): # noqa | |||
'gets unpacked into the [sqlalchemy.MetaData]' | |||
'(http://docs.sqlalchemy.org/en/rel_1_0/core/metadata.html' | |||
'#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 ' |
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.
s/second/seconds/
superset/models/core.py
Outdated
enable_cache=enable_cache, | ||
cache_timeout=(self.get_extra(). | ||
get('metadata_cache_timeout', {}). | ||
get('schema_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.
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 = None
There's a proposal that would allow this to be written as:
cache_timeout = self.get_extra()?['metadata_cache_timeout']?['schema_cache_timeout']
superset/cache_util.py
Outdated
|
||
|
||
def view_cache_key(*unused_args, **unused_kwargs): | ||
args_hash = hash(frozenset(request.args.items())) | ||
return 'view/{}/{}'.format(request.path, args_hash) | ||
|
||
|
||
def memoized_func(timeout=5 * 60, key=view_cache_key): | ||
def default_timetout(*unused_args, **unused_kwargs): |
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.
default_timeout
superset/cache_util.py
Outdated
return True | ||
|
||
|
||
def memoized_func(timeout=default_timetout, |
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.
default_timeout
superset/views/core.py
Outdated
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 inextra
of a database configuration. Ifschema_cache_timeout
is 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 toCacheLabel
but 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.