diff --git a/pkg/gomuks/buffer.go b/pkg/gomuks/buffer.go index 021102e..5171fec 100644 --- a/pkg/gomuks/buffer.go +++ b/pkg/gomuks/buffer.go @@ -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, } diff --git a/pkg/gomuks/config.go b/pkg/gomuks/config.go index 7916ee3..9675bea 100644 --- a/pkg/gomuks/config.go +++ b/pkg/gomuks/config.go @@ -42,11 +42,12 @@ type MatrixConfig struct { } type WebConfig struct { - ListenAddress string `yaml:"listen_address"` - Username string `yaml:"username"` - PasswordHash string `yaml:"password_hash"` - TokenKey string `yaml:"token_key"` - DebugEndpoints bool `yaml:"debug_endpoints"` + ListenAddress string `yaml:"listen_address"` + Username string `yaml:"username"` + 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 }