mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Fixing race condition on status serialization (#14147)
* More atomic serialization process for status * Improving the granularity of tests on api4/status_test.go
This commit is contained in:
@@ -28,10 +28,9 @@ type Status struct {
|
||||
}
|
||||
|
||||
func (o *Status) ToJson() string {
|
||||
tempChannelId := o.ActiveChannel
|
||||
o.ActiveChannel = ""
|
||||
b, _ := json.Marshal(o)
|
||||
o.ActiveChannel = tempChannelId
|
||||
oCopy := *o
|
||||
oCopy.ActiveChannel = ""
|
||||
b, _ := json.Marshal(oCopy)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
@@ -47,18 +46,14 @@ func StatusFromJson(data io.Reader) *Status {
|
||||
}
|
||||
|
||||
func StatusListToJson(u []*Status) string {
|
||||
activeChannels := make([]string, len(u))
|
||||
for index, s := range u {
|
||||
activeChannels[index] = s.ActiveChannel
|
||||
s.ActiveChannel = ""
|
||||
}
|
||||
|
||||
b, _ := json.Marshal(u)
|
||||
|
||||
for index, s := range u {
|
||||
s.ActiveChannel = activeChannels[index]
|
||||
uCopy := make([]Status, len(u))
|
||||
for i, s := range u {
|
||||
sCopy := *s
|
||||
sCopy.ActiveChannel = ""
|
||||
uCopy[i] = sCopy
|
||||
}
|
||||
|
||||
b, _ := json.Marshal(uCopy)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user