- 前端: 所有界面显示、i18n 文本、组件中的品牌名称 - 后端: 服务层、设置默认值、邮件模板、安装向导 - 数据库: 迁移脚本注释 - 保持功能完全一致,仅更改品牌名称 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
package service
|
|
|
|
import (
|
|
"strconv"
|
|
"testing"
|
|
)
|
|
|
|
var benchmarkStringSink string
|
|
|
|
// BenchmarkGenerateSessionHash_Metadata 关注 JSON 解析与正则匹配开销。
|
|
func BenchmarkGenerateSessionHash_Metadata(b *testing.B) {
|
|
svc := &GatewayService{}
|
|
body := []byte(`{"metadata":{"user_id":"session_123e4567-e89b-12d3-a456-426614174000"},"messages":[{"content":"hello"}]}`)
|
|
|
|
b.ReportAllocs()
|
|
for i := 0; i < b.N; i++ {
|
|
parsed, err := ParseGatewayRequest(body)
|
|
if err != nil {
|
|
b.Fatalf("解析请求失败: %v", err)
|
|
}
|
|
benchmarkStringSink = svc.GenerateSessionHash(parsed)
|
|
}
|
|
}
|
|
|
|
// BenchmarkExtractCacheableContent_System 关注字符串拼接路径的性能。
|
|
func BenchmarkExtractCacheableContent_System(b *testing.B) {
|
|
svc := &GatewayService{}
|
|
req := buildSystemCacheableRequest(12)
|
|
|
|
b.ReportAllocs()
|
|
for i := 0; i < b.N; i++ {
|
|
benchmarkStringSink = svc.extractCacheableContent(req)
|
|
}
|
|
}
|
|
|
|
func buildSystemCacheableRequest(parts int) *ParsedRequest {
|
|
systemParts := make([]any, 0, parts)
|
|
for i := 0; i < parts; i++ {
|
|
systemParts = append(systemParts, map[string]any{
|
|
"text": "system_part_" + strconv.Itoa(i),
|
|
"cache_control": map[string]any{
|
|
"type": "ephemeral",
|
|
},
|
|
})
|
|
}
|
|
return &ParsedRequest{
|
|
System: systemParts,
|
|
HasSystem: true,
|
|
}
|
|
}
|