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
}
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++
}
if err := scanner.Err(); err != nil {
return 0, err
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) {

Loading…
Cancel
Save