diff options
author | =Corey Hulen <corey@hulen.com> | 2015-07-12 19:12:23 -0800 |
---|---|---|
committer | =Corey Hulen <corey@hulen.com> | 2015-07-12 19:12:23 -0800 |
commit | 443a386f775dba732fa788625dc99438d16d3931 (patch) | |
tree | 7b879e2e31fc46d9feb2262a775fd09003b4bffc | |
parent | cf11d387eef7883d8c2866d8bb44887120499963 (diff) | |
download | chat-443a386f775dba732fa788625dc99438d16d3931.tar.gz chat-443a386f775dba732fa788625dc99438d16d3931.tar.bz2 chat-443a386f775dba732fa788625dc99438d16d3931.zip |
minor tweaks to make sure mysql still runs
-rw-r--r-- | api/post_test.go | 1 | ||||
-rw-r--r-- | config/config.json | 6 | ||||
-rw-r--r-- | model/client.go | 2 | ||||
-rw-r--r-- | store/sql_channel_store.go | 24 | ||||
-rw-r--r-- | store/sql_post_store.go | 4 |
5 files changed, 28 insertions, 9 deletions
diff --git a/api/post_test.go b/api/post_test.go index 970307759..3af1874c2 100644 --- a/api/post_test.go +++ b/api/post_test.go @@ -516,6 +516,7 @@ func TestDeletePosts(t *testing.T) { post3a1 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a", RootId: post3.Id} post3a1 = Client.Must(Client.CreatePost(post3a1)).Data.(*model.Post) + time.Sleep(10 * time.Millisecond) Client.Must(Client.DeletePost(channel1.Id, post3.Id)) r2 := Client.Must(Client.GetPosts(channel1.Id, 0, 10, "")).Data.(*model.PostList) diff --git a/config/config.json b/config/config.json index b4cac09f1..b0a019e8d 100644 --- a/config/config.json +++ b/config/config.json @@ -23,9 +23,9 @@ "AnalyticsUrl": "" }, "SqlSettings": { - "DriverName": "postgres", - "DataSource": "postgres://mmuser:password@localhost:5432/mattermost_test?sslmode=disable&connect_timeout=10", - "DataSourceReplicas": ["postgres://mmuser:password@localhost:5432/mattermost_test?sslmode=disable&connect_timeout=10"], + "DriverName": "mysql", + "DataSource": "mmuser:mostest@tcp(dockerhost:3306)/mattermost_test", + "DataSourceReplicas": ["mmuser:mostest@tcp(dockerhost:3306)/mattermost_test"], "MaxIdleConns": 10, "MaxOpenConns": 10, "Trace": false, diff --git a/model/client.go b/model/client.go index ab01e7d62..e22f2308e 100644 --- a/model/client.go +++ b/model/client.go @@ -11,6 +11,7 @@ import ( "net/url" "strconv" "strings" + "time" ) const ( @@ -92,6 +93,7 @@ func getCookie(name string, resp *http.Response) *http.Cookie { func (c *Client) Must(result *Result, err *AppError) *Result { if err != nil { + time.Sleep(time.Second) panic(err) } diff --git a/store/sql_channel_store.go b/store/sql_channel_store.go index 9dabf6c30..717f54d05 100644 --- a/store/sql_channel_store.go +++ b/store/sql_channel_store.go @@ -482,8 +482,10 @@ func (s SqlChannelStore) UpdateLastViewedAt(channelId string, userId string) Sto go func() { result := StoreResult{} - _, err := s.GetMaster().Exec( - `UPDATE + var query string + + if utils.Cfg.SqlSettings.DriverName == "postgres" { + query = `UPDATE ChannelMembers SET MentionCount = 0, @@ -495,8 +497,22 @@ func (s SqlChannelStore) UpdateLastViewedAt(channelId string, userId string) Sto WHERE Channels.Id = ChannelMembers.ChannelId AND UserId = :UserId - AND ChannelId = :ChannelId`, - map[string]interface{}{"ChannelId": channelId, "UserId": userId}) + AND ChannelId = :ChannelId` + } else if utils.Cfg.SqlSettings.DriverName == "mysql" { + query = `UPDATE + ChannelMembers, Channels + SET + ChannelMembers.MentionCount = 0, + ChannelMembers.MsgCount = Channels.TotalMsgCount, + ChannelMembers.LastViewedAt = Channels.LastPostAt, + ChannelMembers.LastUpdateAt = Channels.LastPostAt + WHERE + Channels.Id = ChannelMembers.ChannelId + AND UserId = :UserId + AND ChannelId = :ChannelId` + } + + _, err := s.GetMaster().Exec(query, map[string]interface{}{"ChannelId": channelId, "UserId": userId}) if err != nil { result.Err = model.NewAppError("SqlChannelStore.UpdateLastViewedAt", "We couldn't update the last viewed at time", "channel_id="+channelId+", user_id="+userId+", "+err.Error()) } diff --git a/store/sql_post_store.go b/store/sql_post_store.go index 3aab1a05d..f557fb05c 100644 --- a/store/sql_post_store.go +++ b/store/sql_post_store.go @@ -295,7 +295,7 @@ func (s SqlPostStore) getRootPosts(channelId string, offset int, limit int) Stor result := StoreResult{} var posts []*model.Post - _, err := s.GetReplica().Select(&posts, "SELECT * FROM Posts WHERE ChannelId = :ChannelId AND DeleteAt = 0 ORDER BY CreateAt DESC OFFSET :Offset LIMIT :Limit", map[string]interface{}{"ChannelId": channelId, "Offset": offset, "Limit": limit}) + _, err := s.GetReplica().Select(&posts, "SELECT * FROM Posts WHERE ChannelId = :ChannelId AND DeleteAt = 0 ORDER BY CreateAt DESC LIMIT :Limit OFFSET :Offset", map[string]interface{}{"ChannelId": channelId, "Offset": offset, "Limit": limit}) if err != nil { result.Err = model.NewAppError("SqlPostStore.GetLinearPosts", "We couldn't get the posts for the channel", "channelId="+channelId+err.Error()) } else { @@ -333,7 +333,7 @@ func (s SqlPostStore) getParentsPosts(channelId string, offset int, limit int) S ChannelId = :ChannelId1 AND DeleteAt = 0 ORDER BY CreateAt DESC - OFFSET :Offset LIMIT :Limit) q3) q1 ON q1.RootId = q2.RootId + LIMIT :Limit OFFSET :Offset) q3) q1 ON q1.RootId = q2.RootId WHERE ChannelId = :ChannelId2 AND DeleteAt = 0 |