Skip to content

Commit

Permalink
Fixing race in update channel (mattermost#7269)
Browse files Browse the repository at this point in the history
* Fixing race in update channel

* Switching to struct copy
  • Loading branch information
coreyhulen authored Aug 22, 2017
1 parent 1ce079d commit b0e367b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions model/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ type ChannelPatch struct {
Purpose *string `json:"purpose"`
}

func (o *Channel) DeepCopy() *Channel {
copy := *o
return &copy
}

func (o *Channel) ToJson() string {
b, err := json.Marshal(o)
if err != nil {
Expand Down
9 changes: 9 additions & 0 deletions model/channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ func TestChannelJson(t *testing.T) {
}
}

func TestChannelCopy(t *testing.T) {
o := Channel{Id: NewId(), Name: NewId()}
ro := o.DeepCopy()

if o.Id != ro.Id {
t.Fatal("Ids do not match")
}
}

func TestChannelPatch(t *testing.T) {
p := &ChannelPatch{Name: new(string), DisplayName: new(string), Header: new(string), Purpose: new(string)}
*p.Name = NewId()
Expand Down
2 changes: 1 addition & 1 deletion store/sql_channel_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ func (s SqlChannelStore) get(id string, master bool, allowFromCache bool) StoreC
if metrics != nil {
metrics.IncrementMemCacheHitCounter("Channel")
}
result.Data = cacheItem.(*model.Channel)
result.Data = (cacheItem.(*model.Channel)).DeepCopy()
storeChannel <- result
close(storeChannel)
return
Expand Down

0 comments on commit b0e367b

Please sign in to comment.