dpgaspar commented on code in PR #23853: URL: https://github.com/apache/superset/pull/23853#discussion_r1187180019
########## superset/cachekeys/commands/warm_up_cache.py: ########## @@ -0,0 +1,116 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + + +from typing import Any, Dict, List, Optional + +import simplejson as json +from flask import g + +from superset.cachekeys.commands.exceptions import ( + WarmUpCacheChartNotFoundError, + WarmUpCacheParametersExpectedError, + WarmUpCacheTableNotFoundError, +) +from superset.commands.base import BaseCommand +from superset.connectors.sqla.models import SqlaTable +from superset.extensions import db +from superset.models.core import Database +from superset.models.slice import Slice +from superset.utils.core import error_msg_from_exception +from superset.views.utils import get_dashboard_extra_filters, get_form_data, get_viz + + +class WarmUpCacheCommand(BaseCommand): + # pylint: disable=too-many-arguments + def __init__( + self, + chart_id: Optional[int], + dashboard_id: Optional[int], + table_name: Optional[str], + db_name: Optional[str], + extra_filters: Optional[str], + ): + self._chart_id = chart_id + self._dashboard_id = dashboard_id + self._table_name = table_name + self._db_name = db_name + self._extra_filters = extra_filters + self._charts: List[Slice] = [] + + def run(self) -> List[Dict[str, Any]]: + self.validate() + result: List[Dict[str, Any]] = [] + for chart in self._charts: + try: + form_data = get_form_data(chart.id, use_slice_data=True)[0] + if self._dashboard_id: + form_data["extra_filters"] = ( + json.loads(self._extra_filters) + if self._extra_filters + else get_dashboard_extra_filters(chart.id, self._dashboard_id) + ) + + if not chart.datasource: + raise Exception("Slice's datasource does not exist") Review Comment: nit: change it to `Chart's datasets does not exist` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
