Skip to content
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

[cache] Cleaning up viz/cache logic #9375

Merged
merged 1 commit into from
Mar 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions superset/common/query_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ def get_df_payload( # pylint: disable=too-many-locals,too-many-statements
df = query_result["df"]
if status != utils.QueryStatus.FAILED:
stats_logger.incr("loaded_from_source")
if not self.force:
stats_logger.incr("loaded_from_source_without_force")
is_loaded = True
except Exception as e: # pylint: disable=broad-except
logger.exception(e)
Expand Down
17 changes: 0 additions & 17 deletions superset/models/slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,23 +232,6 @@ def slice_link(self) -> Markup:
def changed_by_url(self) -> str:
return f"/superset/profile/{self.created_by.username}"

def get_viz(self, force: bool = False) -> BaseViz:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused after removing the /slice_query/<slice_id>/ endpoint.

"""Creates :py:class:viz.BaseViz object from the url_params_multidict.

:return: object of the 'viz_type' type that is taken from the
url_params_multidict or self.params.
:rtype: :py:class:viz.BaseViz
"""
slice_params = json.loads(self.params)
slice_params["slice_id"] = self.id
slice_params["json"] = "false"
slice_params["slice_name"] = self.slice_name
slice_params["viz_type"] = self.viz_type if self.viz_type else "table"

return viz_types[slice_params.get("viz_type")](
self.datasource, form_data=slice_params, force=force
)

@property
def icons(self) -> str:
return f"""
Expand Down
36 changes: 1 addition & 35 deletions superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def check_datasource_perms(
except SupersetException as e:
raise SupersetSecurityException(str(e))

viz_obj = get_viz(
viz_obj = get_viz( # type: ignore
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seemed cleaner than doing assert datasource_type.

datasource_type=datasource_type,
datasource_id=datasource_id,
form_data=form_data,
Expand Down Expand Up @@ -576,27 +576,6 @@ def clean_fulfilled_requests(session):
session.commit()
return redirect("/accessrequestsmodelview/list/")

def get_viz(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused since the views.utils.get_viz method was added.

self,
slice_id=None,
form_data=None,
datasource_type=None,
datasource_id=None,
force=False,
):
if slice_id:
slc = db.session.query(Slice).filter_by(id=slice_id).one()
return slc.get_viz()
else:
viz_type = form_data.get("viz_type", "table")
datasource = ConnectorRegistry.get_datasource(
datasource_type, datasource_id, db.session
)
viz_obj = viz.viz_types[viz_type](
datasource, form_data=form_data, force=force
)
return viz_obj

@has_access
@expose("/slice/<slice_id>/")
def slice(self, slice_id):
Expand Down Expand Up @@ -2783,19 +2762,6 @@ def sqllab(self):
"superset/basic.html", entry="sqllab", bootstrap_data=bootstrap_data
)

@api
@handle_api_exception
@has_access_api
@expose("/slice_query/<slice_id>/")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mistercrunch double checking that this is legacy/completely unused

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just greped in the repo and things look 👍

def slice_query(self, slice_id):
"""
This method exposes an API endpoint to
get the database query string for this slice
"""
viz_obj = get_viz(slice_id)
security_manager.assert_viz_permission(viz_obj)
return self.get_query_string_response(viz_obj)

@api
@has_access_api
@expose("/schemas_access_for_csv_upload")
Expand Down
9 changes: 4 additions & 5 deletions superset/views/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,11 @@ def get_permissions(user):


def get_viz(
slice_id=None, form_data=None, datasource_type=None, datasource_id=None, force=False
form_data: Dict[str, Any],
datasource_type: str,
datasource_id: int,
force: bool = False,
):
if slice_id:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused after removing the /slice_query/<slice_id>/ endpoint.

slc = db.session.query(Slice).filter_by(id=slice_id).one()
return slc.get_viz()

viz_type = form_data.get("viz_type", "table")
datasource = ConnectorRegistry.get_datasource(
datasource_type, datasource_id, db.session
Expand Down
2 changes: 2 additions & 0 deletions superset/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,8 @@ def get_df_payload(self, query_obj=None, **kwargs):
df = self.get_df(query_obj)
if self.status != utils.QueryStatus.FAILED:
stats_logger.incr("loaded_from_source")
if not self.force:
stats_logger.incr("loaded_from_source_without_force")
is_loaded = True
except Exception as e:
logger.exception(e)
Expand Down
9 changes: 0 additions & 9 deletions tests/core_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,15 +731,6 @@ def test_slice_id_is_always_logged_correctly_on_ajax_request(self):
self.get_json_resp(slc_url, {"form_data": json.dumps(slc.form_data)})
self.assertEqual(1, qry.count())

def test_slice_query_endpoint(self):
# API endpoint for query string
self.login(username="admin")
slc = self.get_slice("Girls", db.session)
resp = self.get_resp("/superset/slice_query/{}/".format(slc.id))
assert "query" in resp
assert "language" in resp
self.logout()

def test_import_csv(self):
self.login(username="admin")
table_name = "".join(random.choice(string.ascii_uppercase) for _ in range(5))
Expand Down