feat: 优化网站日志在每行数据量大情况下的读取 (#6103)

Refs https://github.com/1Panel-dev/1Panel/issues/6102
pull/6105/head
zhengkunwang 4 months ago committed by GitHub
parent f243d1c9b4
commit d561c86c68
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -72,16 +72,21 @@ func countLines(path string) (int, error) {
return 0, err return 0, err
} }
defer file.Close() defer file.Close()
reader := bufio.NewReader(file)
scanner := bufio.NewScanner(file) count := 0
lineCount := 0 for {
for scanner.Scan() { _, err := reader.ReadString('\n')
lineCount++ if err != nil {
} if err == io.EOF {
if err := scanner.Err(); err != nil { if count > 0 {
return 0, err count++
}
return count, nil
}
return count, err
}
count++
} }
return lineCount, nil
} }
func ReadFileByLine(filename string, page, pageSize int, latest bool) (lines []string, isEndOfFile bool, total int, err error) { func ReadFileByLine(filename string, page, pageSize int, latest bool) (lines []string, isEndOfFile bool, total int, err error) {

Loading…
Cancel
Save