You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2021/11/24 19:24:47 UTC

[GitHub] [superset] craig-rueda commented on a change in pull request #17536: feat: Adds a key-value endpoint to store the state of dashboard filters

craig-rueda commented on a change in pull request #17536:
URL: https://github.com/apache/superset/pull/17536#discussion_r756365749



##########
File path: superset/dashboards/filters_state/dao.py
##########
@@ -0,0 +1,93 @@
+# 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.
+import logging
+from typing import Optional
+
+from sqlalchemy.exc import SQLAlchemyError
+
+from superset.dao.exceptions import (
+    DAOCreateFailedError,
+    DAODeleteFailedError,
+    DAOUpdateFailedError,
+)
+from superset.dashboards.dao import DashboardDAO
+from superset.extensions import cache_manager
+from superset.key_value.utils import cache_key
+
+logger = logging.getLogger(__name__)
+
+
+class KeyValueDAO:
+    @staticmethod
+    def find_by_id(dashboard_id: int, key: str) -> Optional[str]:
+        """
+        Finds a value that has been stored using a particular key
+        """
+        try:
+            dashboard = DashboardDAO.get_by_id_or_slug(str(dashboard_id))
+            if dashboard:
+                return cache_manager.filters_state_cache.get(

Review comment:
       This kinda logic belongs in the CMD layer. The DAO should just fetch/write/update items in the DB. 

##########
File path: superset/dashboards/filters_state/api.py
##########
@@ -0,0 +1,234 @@
+# 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.
+import logging
+from typing import Type
+
+from flask import Response
+from flask_appbuilder.api import expose, protect, safe
+
+from superset.dashboards.filters_state.dao import KeyValueDAO
+from superset.extensions import event_logger
+from superset.key_value.api import KeyValueRestApi
+from superset.views.base_api import statsd_metrics
+
+logger = logging.getLogger(__name__)
+
+
+class FiltersStateRestApi(KeyValueRestApi):

Review comment:
       `FiltersStateRestApi` -> `DashboardFilterStateRestApi`

##########
File path: superset/dashboards/filters_state/dao.py
##########
@@ -0,0 +1,93 @@
+# 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.
+import logging
+from typing import Optional
+
+from sqlalchemy.exc import SQLAlchemyError
+
+from superset.dao.exceptions import (
+    DAOCreateFailedError,
+    DAODeleteFailedError,
+    DAOUpdateFailedError,
+)
+from superset.dashboards.dao import DashboardDAO
+from superset.extensions import cache_manager
+from superset.key_value.utils import cache_key
+
+logger = logging.getLogger(__name__)
+
+
+class KeyValueDAO:

Review comment:
       This DAO is basically a set of commands as they're not really talking to the DB, other than to delegate to other DAOs. Pls break these out into CMDs instead.




-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org