mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Update Session Props to use one query (#18120)
https://community-daily.mattermost.com/plugins/focalboard/workspace/zyoahc9uapdn3xdptac6jb69ic/285b80a3-257d-41f6-8cf4-ed80ca9d92e5/495cdb4d-c13a-4992-8eb9-80cfee2819a4?c=6f15ea48-995c-4975-8b28-bd58f7d6a34a ```release-note NONE ```
This commit is contained in:
@@ -249,19 +249,15 @@ func (me SqlSessionStore) UpdateDeviceId(id string, deviceId string, expiresAt i
|
||||
}
|
||||
|
||||
func (me SqlSessionStore) UpdateProps(session *model.Session) error {
|
||||
oldSession, err := me.Get(context.Background(), session.Id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
oldSession.Props = session.Props
|
||||
|
||||
count, err := me.GetMaster().Update(oldSession)
|
||||
_, err := me.GetMaster().Exec(`UPDATE Sessions
|
||||
SET Props=:Props
|
||||
WHERE Id=:Id`, map[string]interface{}{
|
||||
"Props": model.MapToJson(session.Props),
|
||||
"Id": session.Id,
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to update Session")
|
||||
}
|
||||
if count != 1 {
|
||||
return fmt.Errorf("updated Sessions were %d, expected 1", count)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -70,6 +70,15 @@ func testSessionGet(t *testing.T, ss store.Store) {
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, session.Id, s1.Id, "should match")
|
||||
|
||||
session.Props[model.SessionPropOs] = "linux"
|
||||
session.Props[model.SessionPropBrowser] = "Chrome"
|
||||
err = ss.Session().UpdateProps(session)
|
||||
require.NoError(t, err)
|
||||
|
||||
session2, err := ss.Session().Get(context.Background(), session.Id)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, session.Props, session2.Props, "should match")
|
||||
|
||||
data, err := ss.Session().GetSessions(s1.UserId)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, data, 3, "should match len")
|
||||
|
||||
Reference in New Issue
Block a user