summaryrefslogtreecommitdiffstats
path: root/store
diff options
context:
space:
mode:
Diffstat (limited to 'store')
-rw-r--r--store/sql_channel_store.go25
-rw-r--r--store/sql_channel_store_test.go4
-rw-r--r--store/sql_upgrade.go3
-rw-r--r--store/store.go2
4 files changed, 25 insertions, 9 deletions
diff --git a/store/sql_channel_store.go b/store/sql_channel_store.go
index a961781dd..47c172f77 100644
--- a/store/sql_channel_store.go
+++ b/store/sql_channel_store.go
@@ -6,6 +6,7 @@ package store
import (
"database/sql"
"fmt"
+ "strconv"
"strings"
l4g "github.com/alecthomas/log4go"
@@ -13,7 +14,6 @@ import (
"github.com/mattermost/platform/einterfaces"
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
- "strconv"
)
const (
@@ -961,13 +961,24 @@ func (s SqlChannelStore) SetLastViewedAt(channelId string, userId string, newLas
return storeChannel
}
-func (s SqlChannelStore) UpdateLastViewedAt(channelId string, userId string) StoreChannel {
+func (s SqlChannelStore) UpdateLastViewedAt(channelIds []string, userId string) StoreChannel {
storeChannel := make(StoreChannel, 1)
go func() {
result := StoreResult{}
var query string
+ props := make(map[string]interface{})
+
+ idQuery := ""
+ for index, channelId := range channelIds {
+ if len(idQuery) > 0 {
+ idQuery += " OR "
+ }
+
+ props["channelId"+strconv.Itoa(index)] = channelId
+ idQuery += "ChannelId = :channelId" + strconv.Itoa(index)
+ }
if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_POSTGRES {
query = `UPDATE
@@ -982,7 +993,7 @@ func (s SqlChannelStore) UpdateLastViewedAt(channelId string, userId string) Sto
WHERE
Channels.Id = ChannelMembers.ChannelId
AND UserId = :UserId
- AND ChannelId = :ChannelId`
+ AND (` + idQuery + `)`
} else if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_MYSQL {
query = `UPDATE
ChannelMembers, Channels
@@ -994,12 +1005,14 @@ func (s SqlChannelStore) UpdateLastViewedAt(channelId string, userId string) Sto
WHERE
Channels.Id = ChannelMembers.ChannelId
AND UserId = :UserId
- AND ChannelId = :ChannelId`
+ AND (` + idQuery + `)`
}
- _, err := s.GetMaster().Exec(query, map[string]interface{}{"ChannelId": channelId, "UserId": userId})
+ props["UserId"] = userId
+
+ _, err := s.GetMaster().Exec(query, props)
if err != nil {
- result.Err = model.NewLocAppError("SqlChannelStore.UpdateLastViewedAt", "store.sql_channel.update_last_viewed_at.app_error", nil, "channel_id="+channelId+", user_id="+userId+", "+err.Error())
+ result.Err = model.NewLocAppError("SqlChannelStore.UpdateLastViewedAt", "store.sql_channel.update_last_viewed_at.app_error", nil, "channel_ids="+strings.Join(channelIds, ",")+", user_id="+userId+", "+err.Error())
}
storeChannel <- result
diff --git a/store/sql_channel_store_test.go b/store/sql_channel_store_test.go
index b2a644c15..64e44cbb3 100644
--- a/store/sql_channel_store_test.go
+++ b/store/sql_channel_store_test.go
@@ -808,12 +808,12 @@ func TestChannelStoreUpdateLastViewedAt(t *testing.T) {
m1.NotifyProps = model.GetDefaultChannelNotifyProps()
Must(store.Channel().SaveMember(&m1))
- err := (<-store.Channel().UpdateLastViewedAt(m1.ChannelId, m1.UserId)).Err
+ err := (<-store.Channel().UpdateLastViewedAt([]string{m1.ChannelId}, m1.UserId)).Err
if err != nil {
t.Fatal("failed to update", err)
}
- err = (<-store.Channel().UpdateLastViewedAt(m1.ChannelId, "missing id")).Err
+ err = (<-store.Channel().UpdateLastViewedAt([]string{m1.ChannelId}, "missing id")).Err
if err != nil {
t.Fatal("failed to update")
}
diff --git a/store/sql_upgrade.go b/store/sql_upgrade.go
index a275f664c..4c4d83504 100644
--- a/store/sql_upgrade.go
+++ b/store/sql_upgrade.go
@@ -225,6 +225,9 @@ func UpgradeDatabaseToVersion36(sqlStore *SqlStore) {
// Add a Position column to users.
sqlStore.CreateColumnIfNotExists("Users", "Position", "varchar(64)", "varchar(64)", "")
+ // Remove ActiveChannel column from Status
+ sqlStore.RemoveColumnIfExists("Status", "ActiveChannel")
+
//saveSchemaVersion(sqlStore, VERSION_3_6_0)
//}
}
diff --git a/store/store.go b/store/store.go
index 8521713d5..2f5065b88 100644
--- a/store/store.go
+++ b/store/store.go
@@ -110,7 +110,7 @@ type ChannelStore interface {
GetMemberCount(channelId string, allowFromCache bool) StoreChannel
RemoveMember(channelId string, userId string) StoreChannel
PermanentDeleteMembersByUser(userId string) StoreChannel
- UpdateLastViewedAt(channelId string, userId string) StoreChannel
+ UpdateLastViewedAt(channelIds []string, userId string) StoreChannel
SetLastViewedAt(channelId string, userId string, newLastViewedAt int64) StoreChannel
IncrementMentionCount(channelId string, userId string) StoreChannel
AnalyticsTypeCount(teamId string, channelType string) StoreChannel