mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-09-06 08:06:43 +08:00
优化日志解析性能
This commit is contained in:
@@ -1,9 +1,4 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { parse } from 'path'
|
|
||||||
|
|
||||||
// 日志列表
|
|
||||||
const logs = ref<string[]>([])
|
|
||||||
|
|
||||||
// 已解析的日志列表
|
// 已解析的日志列表
|
||||||
const parsedLogs = ref<{ level: string; time: string; program: string; content: string }[]>([])
|
const parsedLogs = ref<{ level: string; time: string; program: string; content: string }[]>([])
|
||||||
|
|
||||||
@@ -43,9 +38,23 @@ function startSSELogging() {
|
|||||||
buffer.push(message)
|
buffer.push(message)
|
||||||
if (!timeoutId) {
|
if (!timeoutId) {
|
||||||
timeoutId = window.setTimeout(() => {
|
timeoutId = window.setTimeout(() => {
|
||||||
logs.value.push(...buffer)
|
// 解析新日志
|
||||||
// 限制长度为1000
|
const newParsedLogs = buffer
|
||||||
logs.value = logs.value.slice(-1000)
|
.map(log => {
|
||||||
|
const logPattern = /^【(.*?)】[0-9\-:]*\s(.*?)\s-\s(.*?)\s-\s(.*)$/
|
||||||
|
const matches = log.match(logPattern)
|
||||||
|
if (matches) {
|
||||||
|
const [, level, time, program, content] = matches
|
||||||
|
return { level, time, program, content }
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
})
|
||||||
|
.filter(Boolean)
|
||||||
|
// 倒序后插入parsedLogs顶部
|
||||||
|
parsedLogs.value.unshift(...(newParsedLogs.reverse() as any[]))
|
||||||
|
// 保留最新的200条日志
|
||||||
|
parsedLogs.value = parsedLogs.value.slice(0, 200)
|
||||||
|
// 重置buffer
|
||||||
buffer.length = 0
|
buffer.length = 0
|
||||||
timeoutId = null
|
timeoutId = null
|
||||||
}, 100)
|
}, 100)
|
||||||
@@ -54,29 +63,6 @@ function startSSELogging() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 解析日志并倒序
|
|
||||||
watch(
|
|
||||||
logs,
|
|
||||||
newLogs => {
|
|
||||||
// 解析新日志
|
|
||||||
const newParsedLogs = newLogs
|
|
||||||
.map(log => {
|
|
||||||
const logPattern = /^【(.*?)】[0-9\-:]*\s(.*?)\s-\s(.*?)\s-\s(.*)$/
|
|
||||||
const matches = log.match(logPattern)
|
|
||||||
if (matches) {
|
|
||||||
const [, level, time, program, content] = matches
|
|
||||||
return { level, time, program, content }
|
|
||||||
}
|
|
||||||
return null
|
|
||||||
})
|
|
||||||
.filter(Boolean)
|
|
||||||
|
|
||||||
// 倒序后插入parsedLogs顶部
|
|
||||||
parsedLogs.value = [...(newParsedLogs.reverse() as any[])]
|
|
||||||
},
|
|
||||||
{ deep: true },
|
|
||||||
)
|
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
startSSELogging()
|
startSSELogging()
|
||||||
})
|
})
|
||||||
@@ -87,7 +73,7 @@ onBeforeUnmount(() => {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<LoadingBanner v-if="logs.length === 0" class="mt-12" text="正在刷新 ..." />
|
<LoadingBanner v-if="parsedLogs.length === 0" class="mt-12" text="正在刷新 ..." />
|
||||||
<div v-else>
|
<div v-else>
|
||||||
<VTable class="table-rounded" hide-default-footer disable-sort>
|
<VTable class="table-rounded" hide-default-footer disable-sort>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
|||||||
Reference in New Issue
Block a user