mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-19 00:09:16 +08:00
feat: 优化网站日志在每行数据量大情况下的读取 (#6103)
Refs https://github.com/1Panel-dev/1Panel/issues/6102
This commit is contained in:
parent
f243d1c9b4
commit
d561c86c68
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user