优化: 资源消耗优化,发布 v0.2.1
This commit is contained in:
@@ -128,6 +128,7 @@ func scanAllProjects() ([]*ProjectDir, map[string]*cacheEntry, map[string]bool)
|
||||
dirMap := make(map[string]*ProjectDir)
|
||||
updatedIDs := make(map[string]bool)
|
||||
seenIDs := make(map[string]bool)
|
||||
scanBuf := make([]byte, 0, 64*1024) // 共享扫描缓冲区
|
||||
|
||||
for _, entry := range entries {
|
||||
if !entry.IsDir() {
|
||||
@@ -170,7 +171,7 @@ func scanAllProjects() ([]*ProjectDir, map[string]*cacheEntry, map[string]bool)
|
||||
continue
|
||||
}
|
||||
|
||||
session := scanSessionFile(filePath, sessionID)
|
||||
session := scanSessionFile(filePath, sessionID, &scanBuf)
|
||||
if session == nil || session.Cwd == "" {
|
||||
continue
|
||||
}
|
||||
@@ -246,7 +247,7 @@ func addSessionToDir(dirMap map[string]*ProjectDir, s *Session) {
|
||||
|
||||
const scanLineLimit = 500
|
||||
|
||||
func scanSessionFile(path string, sessionID string) *Session {
|
||||
func scanSessionFile(path string, sessionID string, buf *[]byte) *Session {
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
return nil
|
||||
@@ -255,7 +256,7 @@ func scanSessionFile(path string, sessionID string) *Session {
|
||||
|
||||
s := &Session{ID: sessionID, FilePath: path}
|
||||
scanner := bufio.NewScanner(f)
|
||||
scanner.Buffer(make([]byte, 0, 64*1024), 1024*1024)
|
||||
scanner.Buffer(*buf, 1024*1024)
|
||||
|
||||
lineCount := 0
|
||||
firstMsgFound := false
|
||||
@@ -615,14 +616,12 @@ func updateSummaryInCache(cache map[string]*cacheEntry, sessionID, summary strin
|
||||
entry.AISummary = summary
|
||||
entry.Completed = completed
|
||||
entry.Pending = pending
|
||||
// 异步持久化
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
saveCache(home, cache)
|
||||
// 持久化由 Model.flushCache() 延迟批量写入
|
||||
}
|
||||
|
||||
// cacheFlushMsg 延迟写缓存定时器消息
|
||||
type cacheFlushMsg struct{}
|
||||
|
||||
// --- 收藏 ---
|
||||
|
||||
func favoritesPath(home string) string {
|
||||
|
||||
Reference in New Issue
Block a user