summaryrefslogtreecommitdiffstats
path: root/store
diff options
context:
space:
mode:
authorJoramWilander <jwawilander@gmail.com>2015-12-09 10:48:35 -0500
committerJoramWilander <jwawilander@gmail.com>2015-12-09 10:48:35 -0500
commit8e8b001609a22a0ac82c004e4499207c4b1a41f8 (patch)
treeb1a99928d14daf69735a3aa7e416ac946242db75 /store
parentb612c61ac164dd6a92896bc0892b6566edc298ce (diff)
downloadchat-8e8b001609a22a0ac82c004e4499207c4b1a41f8.tar.gz
chat-8e8b001609a22a0ac82c004e4499207c4b1a41f8.tar.bz2
chat-8e8b001609a22a0ac82c004e4499207c4b1a41f8.zip
Split db channel get into two functions using master and replica
Diffstat (limited to 'store')
-rw-r--r--store/sql_channel_store.go20
-rw-r--r--store/store.go1
2 files changed, 18 insertions, 3 deletions
diff --git a/store/sql_channel_store.go b/store/sql_channel_store.go
index 728f44bc9..b68774189 100644
--- a/store/sql_channel_store.go
+++ b/store/sql_channel_store.go
@@ -241,13 +241,27 @@ func (s SqlChannelStore) extraUpdated(channel *model.Channel) StoreChannel {
}
func (s SqlChannelStore) Get(id string) StoreChannel {
+ return s.get(id, false)
+}
+
+func (s SqlChannelStore) GetFromMaster(id string) StoreChannel {
+ return s.get(id, true)
+}
+
+func (s SqlChannelStore) get(id string, master bool) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
result := StoreResult{}
- // reading from master due to expected race condition when creating channels
- if obj, err := s.GetMaster().Get(model.Channel{}, id); err != nil {
+ var db *gorp.DbMap
+ if master {
+ db = s.GetMaster()
+ } else {
+ db = s.GetReplica()
+ }
+
+ if obj, err := db.Get(model.Channel{}, id); err != nil {
result.Err = model.NewAppError("SqlChannelStore.Get", "We encountered an error finding the channel", "id="+id+", "+err.Error())
} else if obj == nil {
result.Err = model.NewAppError("SqlChannelStore.Get", "We couldn't find the existing channel", "id="+id)
@@ -439,7 +453,7 @@ func (s SqlChannelStore) SaveMember(member *model.ChannelMember) StoreChannel {
go func() {
var result StoreResult
// Grab the channel we are saving this member to
- if cr := <-s.Get(member.ChannelId); cr.Err != nil {
+ if cr := <-s.GetFromMaster(member.ChannelId); cr.Err != nil {
result.Err = cr.Err
} else {
channel := cr.Data.(*model.Channel)
diff --git a/store/store.go b/store/store.go
index 0695ea27f..682195148 100644
--- a/store/store.go
+++ b/store/store.go
@@ -60,6 +60,7 @@ type ChannelStore interface {
SaveDirectChannel(channel *model.Channel, member1 *model.ChannelMember, member2 *model.ChannelMember) StoreChannel
Update(channel *model.Channel) StoreChannel
Get(id string) StoreChannel
+ GetFromMaster(id string) StoreChannel
Delete(channelId string, time int64) StoreChannel
PermanentDeleteByTeam(teamId string) StoreChannel
GetByName(team_id string, domain string) StoreChannel