mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-19 08:19:15 +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
|
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 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) {
|
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