2
0
mirror of https://github.com/acepanel/panel.git synced 2026-02-04 07:57:21 +08:00

Revert "feat: 尝试改善日志性能"

This reverts commit 5ac43df821.
This commit is contained in:
耗子
2024-10-26 02:33:18 +08:00
parent 049f708cae
commit 9dfc1d3058

View File

@@ -4,9 +4,7 @@ import (
"bufio"
"context"
"net/http"
"strings"
"sync"
"time"
"github.com/gorilla/websocket"
@@ -103,28 +101,10 @@ func (s *WsService) Exec(w http.ResponseWriter, r *http.Request) {
go func() {
scanner := bufio.NewScanner(out)
var batch []string
ticker := time.NewTicker(200 * time.Millisecond)
defer ticker.Stop()
go func() {
for range ticker.C {
if len(batch) > 0 {
_ = ws.WriteMessage(websocket.TextMessage, []byte(strings.Join(batch, "\n")))
batch = nil
}
}
}()
for scanner.Scan() {
line := scanner.Text()
batch = append(batch, line)
_ = ws.WriteMessage(websocket.TextMessage, []byte(line))
}
if len(batch) > 0 {
_ = ws.WriteMessage(websocket.TextMessage, []byte(strings.Join(batch, "\n")))
}
if err = scanner.Err(); err != nil {
_ = ws.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, "failed to read command output"))
}