fmt.Sprintf was badly optimized and in cases of heavy traffic,
it was in the hot path and caused a lot of allocations.
We sacrifice readability for performance here.
```
10:46:40-~/mattermost/mattermost-server/model] benchstat base.txt new.txt
goos: linux
goarch: amd64
pkg: github.com/mattermost/mattermost-server/v6/model
cpu: Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz
│ base.txt │ new.txt │
│ sec/op │ sec/op vs base │
EncodeJSON-8 2.061µ ± 1% 1.588µ ± 2% -22.93% (p=0.000 n=10)
│ base.txt │ new.txt │
│ B/op │ B/op vs base │
EncodeJSON-8 545.0 ± 0% 472.0 ± 0% -13.39% (p=0.000 n=10)
│ base.txt │ new.txt │
│ allocs/op │ allocs/op vs base │
EncodeJSON-8 6.000 ± 0% 3.000 ± 0% -50.00% (p=0.000 n=10)
```
```release-note
Writes to websocket now take 13% less memory
and also 22% faster per message.
```
* MM-48614: saves priority for drafts
Adds a new column in the drafts table, "priority".
This way we can save post's priority in the draft.
Fixes OmitConnectionId, which when you published a ws event for a user
was getting bypassed.
Fixes Get for drafts returns deleted ones as well, which is needed for
upsert.
* Adds test case for the OmitConnectionId
* Addresses review comments, removes DeleteAt
* Vets
* Adds missing translation
* Re-instates DeleteAt column
* Adds separate case to get draft including deleted
* Fixes Update Draft
* Empty
* Adds OmitConnection parameter to broadcast
Currently we have no means to omit sending a websocket event to a
specific connection id.
This is needed mainly so that the initiator won't receive an event for
the action it just initiated.
Will be used for the global drafts feature, so that we won't update
drafts through ws when a user is typing.
This commit adds OmitConnection to the Broadcast struct and to the
NewWebSocketEvent function signature.
shouldSendEvent should return false for that specific connection.
* Return early only if connection id matches the omitted
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
* MM-25516: Changed to byte slice instead of string for cluster messages
https://mattermost.atlassian.net/browse/MM-25116
Testing:
Manually tested.
Load-tested with Cluster Controller.
I looked into changing the serialization method to use msgpack,
but the ClusterMessage struct was mainly used for only 3 fields
which didn't lead to much of a CPU time improvement, whereas
actually led to more allocations using msgpack. Hence, I chose
to remain with JSON.
```
name old time/op new time/op delta
ClusterMarshal-8 3.51µs ± 1% 3.10µs ± 2% -11.59% (p=0.000 n=9+10)
name old alloc/op new alloc/op delta
ClusterMarshal-8 776B ± 0% 1000B ± 0% +28.87% (p=0.000 n=10+10)
name old allocs/op new allocs/op delta
ClusterMarshal-8 12.0 ± 0% 13.0 ± 0% +8.33% (p=0.000 n=10+10)
```
```release-note
Changed the field type of Data in model.ClusterMessage to []byte from string.
```
* Trigger CI
```release-note
NONE
```
* MM-21481: Fixed several issues from user marshalling
- Fixed the root cause for panic by properly converting
the map to a User struct.
- Added a check for type conversion for extra safety.
- Fixed a somewhat unrelated issue of a pointer to pointer reference.
* Fix tests
* Make WebSocketEvent type immutable
* Update code to use updated immutable WebSocketEvent type
* Export WebSocketEvent fields and mark them as deprecated
* Consistent license message for all the go files
* Fixing the last set of unconsistencies with the license headers
* Addressing PR review comments
* Fixing busy.go and busy_test.go license header