功能:实现 webapp 基于索引的日志导航

主要改进:
- 添加索引导航支持:前进/后退按钮现在基于记录索引加载数据
- 后端 API 支持可选的 index 参数,返回包含 centerIndex 的响应
- 前端追踪 currentCenterIndex,实现精确的页面跳转
- 在状态徽章中显示记录索引号 [#索引]
- 修复日志显示逻辑:从追加模式改为完全重新渲染

代码优化:
- concurrent: 使用 Go 1.25 range 语法和 min 函数
- concurrent: 使用 WaitGroup.Go 方法简化 goroutine 启动
- topic_processor: 修正格式化输出

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-10-04 01:43:48 +08:00
parent 3d82a6845e
commit 48b0b56ce7
3 changed files with 115 additions and 66 deletions

View File

@@ -114,12 +114,12 @@ func main() {
var totalQueries atomic.Int64
var queryErrors atomic.Int64
for i := 0; i < queryCount; i++ {
for i := range queryCount {
queryWg.Add(1)
go func(queryID int) {
defer queryWg.Done()
for j := 0; j < queriesPerGoroutine; j++ {
for j := range queriesPerGoroutine {
// 随机选择一个 topic 进行查询
topic := topics[j%len(topics)]
@@ -136,10 +136,7 @@ func main() {
}
// 查询最新的 10 条记录
querySize := 10
if count < querySize {
querySize = count
}
querySize := min(count, 10)
_, err = processor.QueryNewest(count-1, querySize)
if err != nil {
@@ -180,7 +177,7 @@ func main() {
go func(topicName string) {
defer mixWg.Done()
for j := 0; j < 1000; j++ {
for j := range 1000 {
data := fmt.Sprintf("mix-%s-msg-%d", topicName, j)
if _, err := seq.Write(topicName, []byte(data)); err == nil {
@@ -194,12 +191,12 @@ func main() {
}
// 启动查询 goroutine
for i := 0; i < 10; i++ {
for i := range 10 {
mixWg.Add(1)
go func(queryID int) {
defer mixWg.Done()
for j := 0; j < 200; j++ {
for j := range 200 {
topic := topics[j%len(topics)]
processor, err := seq.GetProcessor(topic)
@@ -267,7 +264,7 @@ func main() {
}
// 持续查询 goroutine
for i := 0; i < 5; i++ {
for i := range 5 {
stressWg.Add(1)
go func(queryID int) {
defer stressWg.Done()
@@ -296,8 +293,7 @@ func main() {
}
// 进度显示 goroutine
stressWg.Add(1)
go func() {
stressWg.Go(func() {
defer stressWg.Done()
ticker := time.NewTicker(10 * time.Second)
defer ticker.Stop()
@@ -314,7 +310,7 @@ func main() {
stressQueryCount.Load())
}
}
}()
})
stressWg.Wait()
stressDuration := time.Since(stressTestStart)