Skip to content

Commit

Permalink
cached updatedAt time was not kept in sync with db
Browse files Browse the repository at this point in the history
  • Loading branch information
or-else committed Nov 20, 2019
1 parent b175d9e commit 941b9d5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 6 additions & 2 deletions server/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,9 @@ func (UsersObjMapper) UpdateLastSeen(uid types.Uid, userAgent string, when time.

// Update is a generic user data update.
func (UsersObjMapper) Update(uid types.Uid, update map[string]interface{}) error {
update["UpdatedAt"] = types.TimeNow()
if _, ok := update["UpdatedAt"]; !ok {
update["UpdatedAt"] = types.TimeNow()
}
return adp.UserUpdate(uid, update)
}

Expand Down Expand Up @@ -454,7 +456,9 @@ func (TopicsObjMapper) GetSubsAny(topic string, opts *types.QueryOpt) ([]types.S

// Update is a generic topic update.
func (TopicsObjMapper) Update(topic string, update map[string]interface{}) error {
update["UpdatedAt"] = types.TimeNow()
if _, ok := update["UpdatedAt"]; !ok {
update["UpdatedAt"] = types.TimeNow()
}
return adp.TopicUpdate(topic, update)
}

Expand Down
7 changes: 6 additions & 1 deletion server/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ func (t *Topic) run(hub *Hub) {
userData, userFound := t.perUser[from]
// Anyone is allowed to post to 'sys' topic.
if t.cat != types.TopicCatSys {
// If it's not 'sys' check write permission.
if !(userData.modeWant & userData.modeGiven).IsWriter() {
msg.sess.queueOut(ErrPermissionDenied(msg.id, t.original(asUid),
msg.timestamp))
Expand Down Expand Up @@ -1476,6 +1477,7 @@ func (t *Topic) replySetDesc(sess *Session, asUid types.Uid, set *MsgClientSet)
}

if len(core) > 0 {
core["UpdatedAt"] = now
switch t.cat {
case types.TopicCatMe:
err = store.Users.Update(asUid, core)
Expand Down Expand Up @@ -1514,6 +1516,7 @@ func (t *Topic) replySetDesc(sess *Session, asUid types.Uid, set *MsgClientSet)
if private, ok := sub["Private"]; ok {
pud := t.perUser[asUid]
pud.private = private
pud.updated = now
t.perUser[asUid] = pud
}

Expand All @@ -1527,6 +1530,8 @@ func (t *Topic) replySetDesc(sess *Session, asUid types.Uid, set *MsgClientSet)
// He will be notified separately (see below).
t.presSubsOffline("upd", nilPresParams, &presFilters{excludeUser: asUid.UserId()}, sess.sid, false)
}

t.updated = now
}
// Notify user's other sessions.
t.presSingleUserOffline(asUid, "upd", nilPresParams, sess.sid, false)
Expand Down Expand Up @@ -1937,7 +1942,7 @@ func (t *Topic) replySetTags(sess *Session, asUid types.Uid, set *MsgClientSet)
} else {
added, removed := stringSliceDelta(t.tags, tags)
if len(added) > 0 || len(removed) > 0 {
update := map[string]interface{}{"Tags": types.StringSlice(tags)}
update := map[string]interface{}{"Tags": types.StringSlice(tags), "UpdatedAt": now}
if t.cat == types.TopicCatMe {
err = store.Users.Update(asUid, update)
} else if t.cat == types.TopicCatGrp {
Expand Down

0 comments on commit 941b9d5

Please sign in to comment.