diff options
author | =Corey Hulen <corey@hulen.com> | 2016-01-20 07:59:56 -0600 |
---|---|---|
committer | =Corey Hulen <corey@hulen.com> | 2016-01-20 07:59:56 -0600 |
commit | f5eb3c1bcb0c7e367f64bd8e5a0d2d5418f8e2ef (patch) | |
tree | c40d7064cd2045c36b5c95db8faa9997497e459a /store | |
parent | 1acd38b7b19521d06d274c42c00ce7072cd92196 (diff) | |
download | chat-f5eb3c1bcb0c7e367f64bd8e5a0d2d5418f8e2ef.tar.gz chat-f5eb3c1bcb0c7e367f64bd8e5a0d2d5418f8e2ef.tar.bz2 chat-f5eb3c1bcb0c7e367f64bd8e5a0d2d5418f8e2ef.zip |
PLT-7 adding loc for db calls audits and prefs
Diffstat (limited to 'store')
-rw-r--r-- | store/sql_audit_store.go | 7 | ||||
-rw-r--r-- | store/sql_audit_store_test.go | 15 | ||||
-rw-r--r-- | store/sql_preference_store.go | 27 | ||||
-rw-r--r-- | store/sql_preference_store_test.go | 43 | ||||
-rw-r--r-- | store/sql_store.go | 4 | ||||
-rw-r--r-- | store/store.go | 22 |
6 files changed, 62 insertions, 56 deletions
diff --git a/store/sql_audit_store.go b/store/sql_audit_store.go index f4fd29aab..720e4f483 100644 --- a/store/sql_audit_store.go +++ b/store/sql_audit_store.go @@ -5,6 +5,7 @@ package store import ( "github.com/mattermost/platform/model" + goi18n "github.com/nicksnyder/go-i18n/i18n" ) type SqlAuditStore struct { @@ -34,7 +35,7 @@ func (s SqlAuditStore) CreateIndexesIfNotExists() { s.CreateIndexIfNotExists("idx_audits_user_id", "Audits", "UserId") } -func (s SqlAuditStore) Save(audit *model.Audit) StoreChannel { +func (s SqlAuditStore) Save(T goi18n.TranslateFunc, audit *model.Audit) StoreChannel { storeChannel := make(StoreChannel) @@ -57,7 +58,7 @@ func (s SqlAuditStore) Save(audit *model.Audit) StoreChannel { return storeChannel } -func (s SqlAuditStore) Get(user_id string, limit int) StoreChannel { +func (s SqlAuditStore) Get(T goi18n.TranslateFunc, user_id string, limit int) StoreChannel { storeChannel := make(StoreChannel) @@ -87,7 +88,7 @@ func (s SqlAuditStore) Get(user_id string, limit int) StoreChannel { return storeChannel } -func (s SqlAuditStore) PermanentDeleteByUser(userId string) StoreChannel { +func (s SqlAuditStore) PermanentDeleteByUser(T goi18n.TranslateFunc, userId string) StoreChannel { storeChannel := make(StoreChannel) diff --git a/store/sql_audit_store_test.go b/store/sql_audit_store_test.go index b395631f1..55147ad6f 100644 --- a/store/sql_audit_store_test.go +++ b/store/sql_audit_store_test.go @@ -5,6 +5,7 @@ package store import ( "github.com/mattermost/platform/model" + "github.com/mattermost/platform/utils" "testing" "time" ) @@ -13,19 +14,19 @@ func TestSqlAuditStore(t *testing.T) { Setup() audit := &model.Audit{UserId: model.NewId(), IpAddress: "ipaddress", Action: "Action"} - Must(store.Audit().Save(audit)) + Must(store.Audit().Save(utils.T, audit)) time.Sleep(100 * time.Millisecond) - Must(store.Audit().Save(audit)) + Must(store.Audit().Save(utils.T, audit)) time.Sleep(100 * time.Millisecond) - Must(store.Audit().Save(audit)) + Must(store.Audit().Save(utils.T, audit)) time.Sleep(100 * time.Millisecond) audit.ExtraInfo = "extra" time.Sleep(100 * time.Millisecond) - Must(store.Audit().Save(audit)) + Must(store.Audit().Save(utils.T, audit)) time.Sleep(100 * time.Millisecond) - c := store.Audit().Get(audit.UserId, 100) + c := store.Audit().Get(utils.T, audit.UserId, 100) result := <-c audits := result.Data.(model.Audits) @@ -37,7 +38,7 @@ func TestSqlAuditStore(t *testing.T) { t.Fatal("Failed to save property for extra info") } - c = store.Audit().Get("missing", 100) + c = store.Audit().Get(utils.T, "missing", 100) result = <-c audits = result.Data.(model.Audits) @@ -45,7 +46,7 @@ func TestSqlAuditStore(t *testing.T) { t.Fatal("Should have returned empty because user_id is missing") } - if r2 := <-store.Audit().PermanentDeleteByUser(audit.UserId); r2.Err != nil { + if r2 := <-store.Audit().PermanentDeleteByUser(utils.T, audit.UserId); r2.Err != nil { t.Fatal(r2.Err) } } diff --git a/store/sql_preference_store.go b/store/sql_preference_store.go index 6302d2f4f..234396058 100644 --- a/store/sql_preference_store.go +++ b/store/sql_preference_store.go @@ -8,6 +8,7 @@ import ( "github.com/go-gorp/gorp" "github.com/mattermost/platform/model" "github.com/mattermost/platform/utils" + goi18n "github.com/nicksnyder/go-i18n/i18n" ) type SqlPreferenceStore struct { @@ -41,7 +42,7 @@ func (s SqlPreferenceStore) CreateIndexesIfNotExists() { s.CreateIndexIfNotExists("idx_preferences_name", "Preferences", "Name") } -func (s SqlPreferenceStore) DeleteUnusedFeatures() { +func (s SqlPreferenceStore) DeleteUnusedFeatures(T goi18n.TranslateFunc) { l4g.Debug("Deleting any unused pre-release features") sql := `DELETE @@ -58,7 +59,7 @@ func (s SqlPreferenceStore) DeleteUnusedFeatures() { s.GetMaster().Exec(sql, queryParams) } -func (s SqlPreferenceStore) Save(preferences *model.Preferences) StoreChannel { +func (s SqlPreferenceStore) Save(T goi18n.TranslateFunc, preferences *model.Preferences) StoreChannel { storeChannel := make(StoreChannel) go func() { @@ -70,7 +71,7 @@ func (s SqlPreferenceStore) Save(preferences *model.Preferences) StoreChannel { result.Err = model.NewAppError("SqlPreferenceStore.Save", "Unable to open transaction to save preferences", err.Error()) } else { for _, preference := range *preferences { - if upsertResult := s.save(transaction, &preference); upsertResult.Err != nil { + if upsertResult := s.save(T, transaction, &preference); upsertResult.Err != nil { result = upsertResult break } @@ -97,7 +98,7 @@ func (s SqlPreferenceStore) Save(preferences *model.Preferences) StoreChannel { return storeChannel } -func (s SqlPreferenceStore) save(transaction *gorp.Transaction, preference *model.Preference) StoreResult { +func (s SqlPreferenceStore) save(T goi18n.TranslateFunc, transaction *gorp.Transaction, preference *model.Preference) StoreResult { result := StoreResult{} if result.Err = preference.IsValid(); result.Err != nil { @@ -139,9 +140,9 @@ func (s SqlPreferenceStore) save(transaction *gorp.Transaction, preference *mode } if count == 1 { - s.update(transaction, preference) + s.update(T, transaction, preference) } else { - s.insert(transaction, preference) + s.insert(T, transaction, preference) } } else { result.Err = model.NewAppError("SqlPreferenceStore.save", "We encountered an error while updating preferences", @@ -151,7 +152,7 @@ func (s SqlPreferenceStore) save(transaction *gorp.Transaction, preference *mode return result } -func (s SqlPreferenceStore) insert(transaction *gorp.Transaction, preference *model.Preference) StoreResult { +func (s SqlPreferenceStore) insert(T goi18n.TranslateFunc, transaction *gorp.Transaction, preference *model.Preference) StoreResult { result := StoreResult{} if err := transaction.Insert(preference); err != nil { @@ -167,7 +168,7 @@ func (s SqlPreferenceStore) insert(transaction *gorp.Transaction, preference *mo return result } -func (s SqlPreferenceStore) update(transaction *gorp.Transaction, preference *model.Preference) StoreResult { +func (s SqlPreferenceStore) update(T goi18n.TranslateFunc, transaction *gorp.Transaction, preference *model.Preference) StoreResult { result := StoreResult{} if _, err := transaction.Update(preference); err != nil { @@ -178,7 +179,7 @@ func (s SqlPreferenceStore) update(transaction *gorp.Transaction, preference *mo return result } -func (s SqlPreferenceStore) Get(userId string, category string, name string) StoreChannel { +func (s SqlPreferenceStore) Get(T goi18n.TranslateFunc, userId string, category string, name string) StoreChannel { storeChannel := make(StoreChannel) go func() { @@ -207,7 +208,7 @@ func (s SqlPreferenceStore) Get(userId string, category string, name string) Sto return storeChannel } -func (s SqlPreferenceStore) GetCategory(userId string, category string) StoreChannel { +func (s SqlPreferenceStore) GetCategory(T goi18n.TranslateFunc, userId string, category string) StoreChannel { storeChannel := make(StoreChannel) go func() { @@ -235,7 +236,7 @@ func (s SqlPreferenceStore) GetCategory(userId string, category string) StoreCha return storeChannel } -func (s SqlPreferenceStore) GetAll(userId string) StoreChannel { +func (s SqlPreferenceStore) GetAll(T goi18n.TranslateFunc, userId string) StoreChannel { storeChannel := make(StoreChannel) go func() { @@ -262,7 +263,7 @@ func (s SqlPreferenceStore) GetAll(userId string) StoreChannel { return storeChannel } -func (s SqlPreferenceStore) PermanentDeleteByUser(userId string) StoreChannel { +func (s SqlPreferenceStore) PermanentDeleteByUser(T goi18n.TranslateFunc, userId string) StoreChannel { storeChannel := make(StoreChannel) go func() { @@ -280,7 +281,7 @@ func (s SqlPreferenceStore) PermanentDeleteByUser(userId string) StoreChannel { return storeChannel } -func (s SqlPreferenceStore) IsFeatureEnabled(feature, userId string) StoreChannel { +func (s SqlPreferenceStore) IsFeatureEnabled(T goi18n.TranslateFunc, feature, userId string) StoreChannel { storeChannel := make(StoreChannel) go func() { diff --git a/store/sql_preference_store_test.go b/store/sql_preference_store_test.go index ec9d1df6c..c93831b37 100644 --- a/store/sql_preference_store_test.go +++ b/store/sql_preference_store_test.go @@ -5,6 +5,7 @@ package store import ( "github.com/mattermost/platform/model" + "github.com/mattermost/platform/utils" "testing" ) @@ -27,24 +28,24 @@ func TestPreferenceSave(t *testing.T) { Value: "value1b", }, } - if count := Must(store.Preference().Save(&preferences)); count != 2 { + if count := Must(store.Preference().Save(utils.T, &preferences)); count != 2 { t.Fatal("got incorrect number of rows saved") } for _, preference := range preferences { - if data := Must(store.Preference().Get(preference.UserId, preference.Category, preference.Name)).(model.Preference); preference != data { + if data := Must(store.Preference().Get(utils.T, preference.UserId, preference.Category, preference.Name)).(model.Preference); preference != data { t.Fatal("got incorrect preference after first Save") } } preferences[0].Value = "value2a" preferences[1].Value = "value2b" - if count := Must(store.Preference().Save(&preferences)); count != 2 { + if count := Must(store.Preference().Save(utils.T, &preferences)); count != 2 { t.Fatal("got incorrect number of rows saved") } for _, preference := range preferences { - if data := Must(store.Preference().Get(preference.UserId, preference.Category, preference.Name)).(model.Preference); preference != data { + if data := Must(store.Preference().Get(utils.T, preference.UserId, preference.Category, preference.Name)).(model.Preference); preference != data { t.Fatal("got incorrect preference after second Save") } } @@ -80,16 +81,16 @@ func TestPreferenceGet(t *testing.T) { }, } - Must(store.Preference().Save(&preferences)) + Must(store.Preference().Save(utils.T, &preferences)) - if result := <-store.Preference().Get(userId, category, name); result.Err != nil { + if result := <-store.Preference().Get(utils.T, userId, category, name); result.Err != nil { t.Fatal(result.Err) } else if data := result.Data.(model.Preference); data != preferences[0] { t.Fatal("got incorrect preference") } // make sure getting a missing preference fails - if result := <-store.Preference().Get(model.NewId(), model.NewId(), model.NewId()); result.Err == nil { + if result := <-store.Preference().Get(utils.T, model.NewId(), model.NewId(), model.NewId()); result.Err == nil { t.Fatal("no error on getting a missing preference") } } @@ -127,9 +128,9 @@ func TestPreferenceGetCategory(t *testing.T) { }, } - Must(store.Preference().Save(&preferences)) + Must(store.Preference().Save(utils.T, &preferences)) - if result := <-store.Preference().GetCategory(userId, category); result.Err != nil { + if result := <-store.Preference().GetCategory(utils.T, userId, category); result.Err != nil { t.Fatal(result.Err) } else if data := result.Data.(model.Preferences); len(data) != 2 { t.Fatal("got the wrong number of preferences") @@ -138,7 +139,7 @@ func TestPreferenceGetCategory(t *testing.T) { } // make sure getting a missing preference category doesn't fail - if result := <-store.Preference().GetCategory(model.NewId(), model.NewId()); result.Err != nil { + if result := <-store.Preference().GetCategory(utils.T, model.NewId(), model.NewId()); result.Err != nil { t.Fatal(result.Err) } else if data := result.Data.(model.Preferences); len(data) != 0 { t.Fatal("shouldn't have got any preferences") @@ -178,9 +179,9 @@ func TestPreferenceGetAll(t *testing.T) { }, } - Must(store.Preference().Save(&preferences)) + Must(store.Preference().Save(utils.T, &preferences)) - if result := <-store.Preference().GetAll(userId); result.Err != nil { + if result := <-store.Preference().GetAll(utils.T, userId); result.Err != nil { t.Fatal(result.Err) } else if data := result.Data.(model.Preferences); len(data) != 3 { t.Fatal("got the wrong number of preferences") @@ -226,9 +227,9 @@ func TestPreferenceDelete(t *testing.T) { }, } - Must(store.Preference().Save(&preferences)) + Must(store.Preference().Save(utils.T, &preferences)) - if result := <-store.Preference().PermanentDeleteByUser(userId); result.Err != nil { + if result := <-store.Preference().PermanentDeleteByUser(utils.T, userId); result.Err != nil { t.Fatal(result.Err) } } @@ -276,29 +277,29 @@ func TestIsFeatureEnabled(t *testing.T) { }, } - Must(store.Preference().Save(&features)) + Must(store.Preference().Save(utils.T, &features)) - if result := <-store.Preference().IsFeatureEnabled(feature1, userId); result.Err != nil { + if result := <-store.Preference().IsFeatureEnabled(utils.T, feature1, userId); result.Err != nil { t.Fatal(result.Err) } else if data := result.Data.(bool); data != true { t.Fatalf("got incorrect setting for feature1, %v=%v", true, data) } - if result := <-store.Preference().IsFeatureEnabled(feature2, userId); result.Err != nil { + if result := <-store.Preference().IsFeatureEnabled(utils.T, feature2, userId); result.Err != nil { t.Fatal(result.Err) } else if data := result.Data.(bool); data != false { t.Fatalf("got incorrect setting for feature2, %v=%v", false, data) } // make sure we get false if something different than "true" or "false" has been saved to database - if result := <-store.Preference().IsFeatureEnabled(feature3, userId); result.Err != nil { + if result := <-store.Preference().IsFeatureEnabled(utils.T, feature3, userId); result.Err != nil { t.Fatal(result.Err) } else if data := result.Data.(bool); data != false { t.Fatalf("got incorrect setting for feature3, %v=%v", false, data) } // make sure false is returned if a non-existent feature is queried - if result := <-store.Preference().IsFeatureEnabled("someOtherFeature", userId); result.Err != nil { + if result := <-store.Preference().IsFeatureEnabled(utils.T, "someOtherFeature", userId); result.Err != nil { t.Fatal(result.Err) } else if data := result.Data.(bool); data != false { t.Fatalf("got incorrect setting for non-existent feature 'someOtherFeature', %v=%v", false, data) @@ -341,9 +342,9 @@ func TestDeleteUnusedFeatures(t *testing.T) { }, } - Must(store.Preference().Save(&features)) + Must(store.Preference().Save(utils.T, &features)) - store.(*SqlStore).preference.(*SqlPreferenceStore).DeleteUnusedFeatures() + store.(*SqlStore).preference.(*SqlPreferenceStore).DeleteUnusedFeatures(utils.T) //make sure features with value "false" have actually been deleted from the database if val, err := store.(*SqlStore).preference.(*SqlPreferenceStore).GetReplica().SelectInt(`SELECT COUNT(*) diff --git a/store/sql_store.go b/store/sql_store.go index d0471fa1e..92776cd23 100644 --- a/store/sql_store.go +++ b/store/sql_store.go @@ -15,7 +15,6 @@ import ( "encoding/json" "errors" "fmt" - l4g "github.com/alecthomas/log4go" "io" sqltrace "log" "math/rand" @@ -23,6 +22,7 @@ import ( "strings" "time" + l4g "github.com/alecthomas/log4go" "github.com/go-gorp/gorp" _ "github.com/go-sql-driver/mysql" _ "github.com/lib/pq" @@ -148,7 +148,7 @@ func NewSqlStore() Store { sqlStore.webhook.(*SqlWebhookStore).CreateIndexesIfNotExists() sqlStore.preference.(*SqlPreferenceStore).CreateIndexesIfNotExists() - sqlStore.preference.(*SqlPreferenceStore).DeleteUnusedFeatures() + sqlStore.preference.(*SqlPreferenceStore).DeleteUnusedFeatures(utils.T) if model.IsPreviousVersion(schemaVersion) || isSchemaVersion07 || isSchemaVersion10 { sqlStore.system.Update(&model.System{Name: "Version", Value: model.CurrentVersion}) diff --git a/store/store.go b/store/store.go index 179cfecd7..be35c6d59 100644 --- a/store/store.go +++ b/store/store.go @@ -4,9 +4,11 @@ package store import ( + "time" + l4g "github.com/alecthomas/log4go" "github.com/mattermost/platform/model" - "time" + goi18n "github.com/nicksnyder/go-i18n/i18n" ) type StoreResult struct { @@ -139,9 +141,9 @@ type SessionStore interface { } type AuditStore interface { - Save(audit *model.Audit) StoreChannel - Get(user_id string, limit int) StoreChannel - PermanentDeleteByUser(userId string) StoreChannel + Save(T goi18n.TranslateFunc, audit *model.Audit) StoreChannel + Get(T goi18n.TranslateFunc, user_id string, limit int) StoreChannel + PermanentDeleteByUser(T goi18n.TranslateFunc, userId string) StoreChannel } type OAuthStore interface { @@ -183,10 +185,10 @@ type WebhookStore interface { } type PreferenceStore interface { - Save(preferences *model.Preferences) StoreChannel - Get(userId string, category string, name string) StoreChannel - GetCategory(userId string, category string) StoreChannel - GetAll(userId string) StoreChannel - PermanentDeleteByUser(userId string) StoreChannel - IsFeatureEnabled(feature, userId string) StoreChannel + Save(T goi18n.TranslateFunc, preferences *model.Preferences) StoreChannel + Get(T goi18n.TranslateFunc, userId string, category string, name string) StoreChannel + GetCategory(T goi18n.TranslateFunc, userId string, category string) StoreChannel + GetAll(T goi18n.TranslateFunc, userId string) StoreChannel + PermanentDeleteByUser(T goi18n.TranslateFunc, userId string) StoreChannel + IsFeatureEnabled(T goi18n.TranslateFunc, feature, userId string) StoreChannel } |