forked from apache/superset
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Improve performance of add dataset page (#21)
* Create celery task to warm up tables in a database schema * Use AntdSelect for table selection in add dataset page * fix linter errors * Use feature flag to control change * Fix imports to original version
- Loading branch information
Showing
3 changed files
with
65 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import logging | ||
|
||
from celery.utils.log import get_task_logger | ||
|
||
from superset import db | ||
from superset.exceptions import SupersetException | ||
from superset.extensions import celery_app | ||
from superset.models.core import Database | ||
|
||
logger = get_task_logger(__name__) | ||
logger.setLevel(logging.INFO) | ||
|
||
|
||
@celery_app.task(name="db_tables_cache_warm_up") | ||
def db_tables_cache_warm_up(database_id: str, schema_name: str): | ||
""" | ||
Warm up tables in a database schema | ||
beat_schedule = { | ||
'db_tables_cache_warm_up': { | ||
'task': 'db_tables_cache_warm_up', | ||
'schedule': crontab(minute='*/10', hour='*'), # every 10 minutes | ||
'kwargs': {'database_id': 1, 'schema_name': 'public'}, | ||
}, | ||
} | ||
""" | ||
session = db.create_scoped_session() | ||
logger.info( | ||
"Warming up database table cache for database_id: %i, schema_name: %s", | ||
database_id, | ||
schema_name, | ||
) | ||
try: | ||
database = session.query(Database).filter_by(id=database_id).one_or_none() | ||
if not database: | ||
logger.error("Database not found, database_id: %i", database_id) | ||
|
||
database.get_all_table_names_in_schema( | ||
schema=schema_name, | ||
force=True, | ||
cache=database.table_cache_enabled, | ||
cache_timeout=database.table_cache_timeout, | ||
) | ||
database.get_all_view_names_in_schema( | ||
schema=schema_name, | ||
force=True, | ||
cache=database.table_cache_enabled, | ||
cache_timeout=database.table_cache_timeout, | ||
) | ||
logger.info( | ||
"Database tables cache warm up succeeded for database_id: %i, schema_name: %s", | ||
database_id, | ||
schema_name, | ||
) | ||
except SupersetException as ex: | ||
logger.exception( | ||
"Superset exception for db_tables_cache_warm_up job database_id: %i, schema_name: %s, message: %s", | ||
database_id, | ||
schema_name, | ||
ex.message, | ||
) |