diff --git a/backend/services/log_query.go b/backend/services/log_query.go index 2c4d16f..4e027c1 100644 --- a/backend/services/log_query.go +++ b/backend/services/log_query.go @@ -23,6 +23,9 @@ import ( "lokistack/repository" ) +// maxLogQueryLimit 单页硬上限。依据:实测每条日志约 671B—— +// 1000 条 ≈ 655KB 响应;而前端结果表**没有虚拟滚动**,1000 行会全部渲染成 +// DOM 节点导致卡顿。前端下拉只给到 1000,超过会被这里静默收敛。 const maxLogQueryLimit = 1000 const logQueryTimeout = 120 * time.Second diff --git a/frontend/src/i18n/locales/en/logs.ts b/frontend/src/i18n/locales/en/logs.ts index c09308a..4336548 100644 --- a/frontend/src/i18n/locales/en/logs.ts +++ b/frontend/src/i18n/locales/en/logs.ts @@ -20,7 +20,7 @@ export default { sourceAria: 'Data source', sourceEmptyOption: 'No data sources available', limitLabel: 'Per page', - limitHint: 'Up to 1000 entries per page; paging keeps only the current page.', + limitHint: 'Default 200 entries (~0.7KB each). For very dense logs, narrow the time range or add filters instead of raising the page size.', rangeInvalid: 'Select a valid start and end time', queryFailed: 'Query failed', }, diff --git a/frontend/src/i18n/locales/zh/logs.ts b/frontend/src/i18n/locales/zh/logs.ts index 58a2e97..56f6e71 100644 --- a/frontend/src/i18n/locales/zh/logs.ts +++ b/frontend/src/i18n/locales/zh/logs.ts @@ -19,7 +19,7 @@ export default { sourceAria: '数据源', sourceEmptyOption: '暂无可用数据源', limitLabel: '每页条数', - limitHint: '每页最多 1000 条,翻页仅保留当前页。', + limitHint: '默认 200 条(每条约 0.7KB)。日志量很大时先收窄时间范围或加过滤条件,比调大每页条数更有效。', rangeInvalid: '请选择有效的起止时间', queryFailed: '查询失败', }, diff --git a/frontend/src/pages/logs/components/LogContextDialog.tsx b/frontend/src/pages/logs/components/LogContextDialog.tsx index 4312dc5..921ecc9 100644 --- a/frontend/src/pages/logs/components/LogContextDialog.tsx +++ b/frontend/src/pages/logs/components/LogContextDialog.tsx @@ -41,7 +41,7 @@ export function LogContextDialog({ context, terms, lines, onLinesChange, onClose diff --git a/frontend/src/pages/logs/index.tsx b/frontend/src/pages/logs/index.tsx index 3ea23fe..e9924e5 100644 --- a/frontend/src/pages/logs/index.tsx +++ b/frontend/src/pages/logs/index.tsx @@ -68,7 +68,9 @@ export default function LogsPage() { const [executedRange, setExecutedRange] = useState<{ start: number; end: number } | null>(null) const [start, setStart] = useState(() => toLocal(new Date(Date.now() - 300000))) const [end, setEnd] = useState(() => toLocal(new Date())) - const [limit, setLimit] = useState(1000) + // 默认 200:实测 671B/条,200 条约 131KB、DOM 200 行渲染顺畅。 + // 后端 maxLogQueryLimit=1000,所以下拉不给 2000/5000(否则静默截断成 1000,是假选项) + const [limit, setLimit] = useState(200) const [queryHistory, setQueryHistory] = useState(readQueryHistory) const [entries, setEntries] = useState([]) const [searched, setSearched] = useState(false) @@ -198,10 +200,10 @@ export default function LogsPage() { return () => window.clearInterval(timer) }, [tail, sourceId, query, limit]) - /** 上下文前后条数:默认 2 条(原来写死 5),选择后记住,弹窗内可随时改 */ + /** 上下文前后条数:默认 5 条(Java 一个异常常拆成 4 条日志,2 条拼不完整),选择后记住 */ const [contextLines, setContextLines] = useState(() => { const saved = Number(localStorage.getItem('logContextLines')) - return saved > 0 && saved <= 50 ? saved : 2 + return saved > 0 && saved <= 50 ? saved : 5 }) /** 记住当前查看上下文的那一行,切换条数时原地重新拉取 */ const [contextRow, setContextRow] = useState(null) @@ -273,7 +275,7 @@ export default function LogsPage() {