perf(logs): 未选命名空间时也加载 app 候选,下拉不再"空的要等"
CI / Backend (go vet + test) (push) Waiting to run
CI / Frontend (lint + build + test) (push) Waiting to run

原来快捷 LogQL 里 app 候选的逻辑是:
  if (!namespace) { setApps([]); return }   // 没选命名空间就直接空列表
所以用户必须先点命名空间,app 下拉才会出现内容 —— 观感就是"app 下拉加载慢",
其实是被这条早退挡住了,而不是请求慢。

改为:没有命名空间时拉一次**全量** app 候选(不传 selector),
选了命名空间后按 `{namespace="..."}` 收窄。两者共用同一套批量接口与缓存,
不会多打 Loki(全量结果本来就会被缓存 60 秒)。
This commit is contained in:
opsx committed 2026-10-31 18:25:58 +00:00
1 parent 5f42ac5486
commit 25a5e57cb3
1 file changed
+5 -2
@@ -118,7 +118,7 @@ export function QuickQueryTemplates({ sourceId, query, onQueryChange, onInsert,
// 3) 记住本次解析出的 label 名(appLabel),拼 selector / 收窄 pod 都用它,
// 否则下拉里显示 79 个、生成的 {app="cex-xxx"} 一条也查不到。
useEffect(() => {
if (!sourceId || !namespace.trim()) {
if (!sourceId) {
setApps([])
setAppLabel('app')
setAppLoading(false)
@@ -126,7 +126,10 @@ export function QuickQueryTemplates({ sourceId, query, onQueryChange, onInsert,
}
let active = true
setAppLoading(true)
const selector = selectorOf({ namespace })
// 没选命名空间时也拉一次**全量** app 候选:
// 原来这里是"空就直接 return",导致用户必须先点命名空间才能看到 app 列表,
// 观感上就是"app 下拉加载慢/加载不出来"。选了命名空间后再按 namespace 收窄。
const selector = namespace.trim() ? selectorOf({ namespace }) : ''
logsApi
.labelValuesBatch(sourceId, ['app', 'service_name', 'container'], selector)
.then(result => {