incorporate channel updateAt into channel counts and pull channel data on channel update

Этот коммит содержится в:
JoramWilander
2015-08-11 08:20:17 -04:00
родитель 6c0fefad15
Коммит 4ec76e059c
5 изменённых файлов: 22 добавлений и 11 удалений

Просмотреть файл

@@ -11,7 +11,8 @@ import (
) )
type ChannelCounts struct { type ChannelCounts struct {
Counts map[string]int64 `json:"counts"` Counts map[string]int64 `json:"counts"`
UpdateTimes map[string]int64 `json:"update_times"`
} }
func (o *ChannelCounts) Etag() string { func (o *ChannelCounts) Etag() string {
@@ -20,9 +21,16 @@ func (o *ChannelCounts) Etag() string {
str += id + strconv.FormatInt(count, 10) str += id + strconv.FormatInt(count, 10)
} }
data := []byte(str) md5Counts := md5.Sum([]byte(str))
return Etag(md5.Sum(data)) var update int64 = 0
for _, u := range o.UpdateTimes {
if u > update {
update = u
}
}
return Etag(md5Counts, update)
} }
func (o *ChannelCounts) ToJson() string { func (o *ChannelCounts) ToJson() string {

Просмотреть файл

@@ -281,9 +281,10 @@ func (s SqlChannelStore) GetMoreChannels(teamId string, userId string) StoreChan
return storeChannel return storeChannel
} }
type channelIdWithCount struct { type channelIdWithCountandUpdateAt struct {
Id string Id string
TotalMsgCount int64 TotalMsgCount int64
UpdateAt int64
} }
func (s SqlChannelStore) GetChannelCounts(teamId string, userId string) StoreChannel { func (s SqlChannelStore) GetChannelCounts(teamId string, userId string) StoreChannel {
@@ -292,16 +293,17 @@ func (s SqlChannelStore) GetChannelCounts(teamId string, userId string) StoreCha
go func() { go func() {
result := StoreResult{} result := StoreResult{}
var data []channelIdWithCount var data []channelIdWithCountandUpdateAt
_, err := s.GetReplica().Select(&data, "SELECT Id, TotalMsgCount FROM Channels WHERE Id IN (SELECT ChannelId FROM ChannelMembers WHERE UserId = :UserId) AND TeamId = :TeamId AND DeleteAt = 0 ORDER BY DisplayName", map[string]interface{}{"TeamId": teamId, "UserId": userId}) _, err := s.GetReplica().Select(&data, "SELECT Id, TotalMsgCount, UpdateAt FROM Channels WHERE Id IN (SELECT ChannelId FROM ChannelMembers WHERE UserId = :UserId) AND TeamId = :TeamId AND DeleteAt = 0 ORDER BY DisplayName", map[string]interface{}{"TeamId": teamId, "UserId": userId})
if err != nil { if err != nil {
result.Err = model.NewAppError("SqlChannelStore.GetChannelCounts", "We couldn't get the channel counts", "teamId="+teamId+", userId="+userId+", err="+err.Error()) result.Err = model.NewAppError("SqlChannelStore.GetChannelCounts", "We couldn't get the channel counts", "teamId="+teamId+", userId="+userId+", err="+err.Error())
} else { } else {
counts := &model.ChannelCounts{Counts: make(map[string]int64)} counts := &model.ChannelCounts{Counts: make(map[string]int64), UpdateTimes: make(map[string]int64)}
for i := range data { for i := range data {
v := data[i] v := data[i]
counts.Counts[v.Id] = v.TotalMsgCount counts.Counts[v.Id] = v.TotalMsgCount
counts.UpdateTimes[v.Id] = v.UpdateAt
} }
result.Data = counts result.Data = counts

Просмотреть файл

@@ -74,7 +74,7 @@ module.exports = React.createClass({
moreChannels = ( moreChannels = (
<table className='more-channel-table table'> <table className='more-channel-table table'>
<tbody> <tbody>
{moreChannels.map(function cMap(channel) { {channels.map(function cMap(channel) {
return ( return (
<tr key={channel.id}> <tr key={channel.id}>
<td> <td>

Просмотреть файл

@@ -161,7 +161,6 @@ module.exports = React.createClass({
AsyncClient.updateLastViewedAt(); AsyncClient.updateLastViewedAt();
} }
} else { } else {
console.log('hit');
AsyncClient.getChannels(); AsyncClient.getChannels();
} }

Просмотреть файл

@@ -99,11 +99,13 @@ function getChannels(force, updateLastViewed, checkVersion) {
} }
var countMap = data.counts; var countMap = data.counts;
var updateAtMap = data.update_times;
for (var id in countMap) { for (var id in countMap) {
var chan = ChannelStore.get(id); var c = ChannelStore.get(id);
var count = countMap[id]; var count = countMap[id];
if (!chan || chan.total_msg_count !== count) { var updateAt = updateAtMap[id];
if (!c || c.total_msg_count !== count || updateAt > c.update_at) {
getChannel(id); getChannel(id);
} }
} }