betodealmeida commented on code in PR #31315:
URL: https://github.com/apache/superset/pull/31315#discussion_r2307559669


##########
superset/models/core.py:
##########
@@ -98,6 +98,48 @@
     from superset.models.sql_lab import Query
 
 
+@contextmanager
+def temporarily_disconnect_db():  # type: ignore
+    """
+    Temporary disconnects the metadata database session.
+
+    This is meant to be used during long, blocking operations, so that we can 
release
+    the database connection for the duration of, for example, a potentially 
long running
+    query against an analytics database.
+
+    The goal here is to lower the number of concurrent connections to the 
metadata
+    database, given that Superset has no control over the duration of the
+    analytics query.
+
+    NOTE: only has an effect if feature flag 
DISABLE_METADATA_DB_DURING_ANALYTICS
+    and using NullPool
+    """
+    pool_type = db.engine.pool.__class__.__name__
+    # Currently only tested/available when used with NullPool
+    do_it = (
+        is_feature_enabled("DISABLE_METADATA_DB_DURING_ANALYTICS")
+        and pool_type == "NullPool"
+    )
+    conn = None

Review Comment:
   You can do:
   
   ```python
   if not (
       is_feature_enabled("DISABLE_METADATA_DB_DURING_ANALYTICS")
       and pool_type == "NullPool"
   ):
       yield None
       return
   ```
   
   So you don't need to check for `if do_it` (as Nike says, just do it 😝 )



-- 
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-unsubscr...@superset.apache.org

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


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

Reply via email to