Skip to content

Commit

Permalink
fix(backend): sql查询性能优化 TencentBlueKing#7666
Browse files Browse the repository at this point in the history
# Reviewed, transaction id: 23178
  • Loading branch information
WytheLi authored and iSecloud committed Nov 7, 2024
1 parent 065f716 commit 4912c21
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion dbm-ui/backend/db_meta/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def ready(self):
from backend.db_meta.signals import update_cluster_status
from backend.db_meta.utils import cache_appcache_data

post_migrate.connect(cache_appcache_data, sender=AppCache)
post_migrate.connect(cache_appcache_data, sender=self)
post_save.connect(cache_appcache_data, sender=AppCache)

post_migrate.connect(init_db_meta, sender=self)
Expand Down
17 changes: 10 additions & 7 deletions dbm-ui/backend/db_meta/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,13 @@ def clean_cc_topo(bk_biz_id=env.DBA_APP_BK_BIZ_ID):


def cache_appcache_data(sender, **kwargs):
data = AppCache.objects.all().values()
appcache_list = list(data) if data else []
appcache_dict = {app["bk_biz_id"]: app for app in data}
# 默认30min过期,稍微晚于周期同步cc拓扑的定时任务(20min)
timeout = 60 * 30
cache.set("appcache_list", appcache_list, timeout=timeout)
cache.set("appcache_dict", appcache_dict, timeout=timeout)
try:
data = AppCache.objects.all().values()
appcache_list = list(data) if data else []
appcache_dict = {app["bk_biz_id"]: app for app in data}
# 默认30min过期,稍微晚于周期同步cc拓扑的定时任务(20min)
timeout = 60 * 30
cache.set("appcache_list", appcache_list, timeout=timeout)
cache.set("appcache_dict", appcache_dict, timeout=timeout)
except Exception as e:
logger.info(f"cache_appcache error: {e}")

0 comments on commit 4912c21

Please sign in to comment.