diff options
author | Corey Hulen <corey@hulen.com> | 2015-07-23 11:21:54 -0800 |
---|---|---|
committer | Corey Hulen <corey@hulen.com> | 2015-07-23 11:21:54 -0800 |
commit | b813234f4cc38e72bb94556d3a4acdcde5071468 (patch) | |
tree | f9a0eb8f9596c91531c6997617b4dd66e05dd317 /store/sql_session_store.go | |
parent | 32e8dddd0cd8532e45f89290a154d5d7911c16dd (diff) | |
parent | 98751a4f65a656839dc3724e72e672b585cb18c9 (diff) | |
download | chat-b813234f4cc38e72bb94556d3a4acdcde5071468.tar.gz chat-b813234f4cc38e72bb94556d3a4acdcde5071468.tar.bz2 chat-b813234f4cc38e72bb94556d3a4acdcde5071468.zip |
Merge pull request #170 from mattermost/mm-1420
Fixes mm-1420 adding initial support for postgres
Diffstat (limited to 'store/sql_session_store.go')
-rw-r--r-- | store/sql_session_store.go | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/store/sql_session_store.go b/store/sql_session_store.go index dddd023e5..d1a06a33c 100644 --- a/store/sql_session_store.go +++ b/store/sql_session_store.go @@ -33,7 +33,8 @@ func (me SqlSessionStore) UpgradeSchemaIfNeeded() { } func (me SqlSessionStore) CreateIndexesIfNotExists() { - me.CreateIndexIfNotExists("idx_user_id", "Sessions", "UserId") + me.CreateIndexIfNotExists("idx_sessions_user_id", "Sessions", "UserId") + me.CreateIndexIfNotExists("idx_sessions_alt_id", "Sessions", "AltId") } func (me SqlSessionStore) Save(session *model.Session) StoreChannel { @@ -105,7 +106,7 @@ func (me SqlSessionStore) GetSessions(userId string) StoreChannel { var sessions []*model.Session - if _, err := me.GetReplica().Select(&sessions, "SELECT * FROM Sessions WHERE UserId = ? ORDER BY LastActivityAt DESC", userId); err != nil { + if _, err := me.GetReplica().Select(&sessions, "SELECT * FROM Sessions WHERE UserId = :UserId ORDER BY LastActivityAt DESC", map[string]interface{}{"UserId": userId}); err != nil { result.Err = model.NewAppError("SqlSessionStore.GetSessions", "We encounted an error while finding user sessions", err.Error()) } else { @@ -125,7 +126,7 @@ func (me SqlSessionStore) Remove(sessionIdOrAlt string) StoreChannel { go func() { result := StoreResult{} - _, err := me.GetMaster().Exec("DELETE FROM Sessions WHERE Id = ? Or AltId = ?", sessionIdOrAlt, sessionIdOrAlt) + _, err := me.GetMaster().Exec("DELETE FROM Sessions WHERE Id = :Id Or AltId = :AltId", map[string]interface{}{"Id": sessionIdOrAlt, "AltId": sessionIdOrAlt}) if err != nil { result.Err = model.NewAppError("SqlSessionStore.RemoveSession", "We couldn't remove the session", "id="+sessionIdOrAlt+", err="+err.Error()) } @@ -143,7 +144,7 @@ func (me SqlSessionStore) CleanUpExpiredSessions(userId string) StoreChannel { go func() { result := StoreResult{} - if _, err := me.GetMaster().Exec("DELETE FROM Sessions WHERE UserId = ? AND ExpiresAt != 0 AND ? > ExpiresAt", userId, model.GetMillis()); err != nil { + if _, err := me.GetMaster().Exec("DELETE FROM Sessions WHERE UserId = :UserId AND ExpiresAt != 0 AND :ExpiresAt > ExpiresAt", map[string]interface{}{"UserId": userId, "ExpiresAt": model.GetMillis()}); err != nil { result.Err = model.NewAppError("SqlSessionStore.CleanUpExpiredSessions", "We encounted an error while deleting expired user sessions", err.Error()) } else { result.Data = userId @@ -162,7 +163,7 @@ func (me SqlSessionStore) UpdateLastActivityAt(sessionId string, time int64) Sto go func() { result := StoreResult{} - if _, err := me.GetMaster().Exec("UPDATE Sessions SET LastActivityAt = ? WHERE Id = ?", time, sessionId); err != nil { + if _, err := me.GetMaster().Exec("UPDATE Sessions SET LastActivityAt = :LastActivityAt WHERE Id = :Id", map[string]interface{}{"LastActivityAt": time, "Id": sessionId}); err != nil { result.Err = model.NewAppError("SqlSessionStore.UpdateLastActivityAt", "We couldn't update the last_activity_at", "sessionId="+sessionId) } else { result.Data = sessionId |