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

Refs https://github.com/1Panel-dev/1Panel/issues/6102
This commit is contained in:
zhengkunwang 2024-08-12 17:58:52 +08:00 committed by GitHub
parent f243d1c9b4
commit d561c86c68
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

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