forked from Mirrors/gomuks
websocket/buffer: make size configurable
This commit is contained in:
parent
894fcb3fa0
commit
149114354a
2 changed files with 12 additions and 6 deletions
|
@ -48,7 +48,7 @@ func NewEventBuffer(maxSize int) *EventBuffer {
|
|||
websocketClosers: make(map[uint64]WebsocketCloseFunc),
|
||||
lastAckedID: make(map[uint64]int64),
|
||||
eventListeners: make(map[uint64]func(*hicli.JSONCommand)),
|
||||
buf: make([]*hicli.JSONCommand, 0, maxSize*2),
|
||||
buf: make([]*hicli.JSONCommand, 0, 32),
|
||||
MaxSize: maxSize,
|
||||
minID: -1,
|
||||
}
|
||||
|
|
|
@ -47,6 +47,7 @@ type WebConfig struct {
|
|||
PasswordHash string `yaml:"password_hash"`
|
||||
TokenKey string `yaml:"token_key"`
|
||||
DebugEndpoints bool `yaml:"debug_endpoints"`
|
||||
EventBufferSize int `yaml:"event_buffer_size"`
|
||||
}
|
||||
|
||||
var defaultFileWriter = zeroconfig.WriterConfig{
|
||||
|
@ -115,12 +116,17 @@ func (gmx *Gomuks) LoadConfig() error {
|
|||
gmx.Config.Web.PasswordHash = string(hash)
|
||||
changed = true
|
||||
}
|
||||
if gmx.Config.Web.EventBufferSize <= 0 {
|
||||
gmx.Config.Web.EventBufferSize = 512
|
||||
changed = true
|
||||
}
|
||||
if changed {
|
||||
err = gmx.SaveConfig()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to save config: %w", err)
|
||||
}
|
||||
}
|
||||
gmx.EventBuffer = NewEventBuffer(gmx.Config.Web.EventBufferSize)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue