diff options
author | Shobhit Gupta <smartyshobhit@gmail.com> | 2018-10-03 13:04:37 -0700 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2018-10-03 16:04:37 -0400 |
commit | 8c03e584c182218c84bebc8af23c70fb0cd203d4 (patch) | |
tree | 90cad75d922dc3d9fb25c4456b342b2b4e642d3b /store | |
parent | 7468f35cb0c86b60f66e1c9228a60da244d3fcc4 (diff) | |
download | chat-8c03e584c182218c84bebc8af23c70fb0cd203d4.tar.gz chat-8c03e584c182218c84bebc8af23c70fb0cd203d4.tar.bz2 chat-8c03e584c182218c84bebc8af23c70fb0cd203d4.zip |
MM-11863 Add KVList method (#9467)
* Add KVList method
* Add KVList method
Add KVList method
* Add pagination support
* Change offset, limit to page, perPage
* Rename constant
Diffstat (limited to 'store')
-rw-r--r-- | store/sqlstore/plugin_store.go | 24 | ||||
-rw-r--r-- | store/store.go | 1 | ||||
-rw-r--r-- | store/storetest/mocks/PluginStore.go | 16 |
3 files changed, 41 insertions, 0 deletions
diff --git a/store/sqlstore/plugin_store.go b/store/sqlstore/plugin_store.go index 23b355f48..e4b79e54a 100644 --- a/store/sqlstore/plugin_store.go +++ b/store/sqlstore/plugin_store.go @@ -12,6 +12,10 @@ import ( "github.com/mattermost/mattermost-server/store" ) +const ( + DEFAULT_PLUGIN_KEY_FETCH_LIMIT = 10 +) + type SqlPluginStore struct { SqlStore } @@ -92,3 +96,23 @@ func (ps SqlPluginStore) Delete(pluginId, key string) store.StoreChannel { } }) } + +func (ps SqlPluginStore) List(pluginId string, offset int, limit int) store.StoreChannel { + if limit <= 0 { + limit = DEFAULT_PLUGIN_KEY_FETCH_LIMIT + } + + if offset <= 0 { + offset = 0 + } + + return store.Do(func(result *store.StoreResult) { + var keys []string + _, err := ps.GetReplica().Select(&keys, "SELECT PKey FROM PluginKeyValueStore WHERE PluginId = :PluginId order by PKey limit :Limit offset :Offset", map[string]interface{}{"PluginId": pluginId, "Limit": limit, "Offset": offset}) + if err != nil { + result.Err = model.NewAppError("SqlPluginStore.List", "store.sql_plugin_store.list.app_error", nil, fmt.Sprintf("plugin_id=%v, err=%v", pluginId, err.Error()), http.StatusInternalServerError) + } else { + result.Data = keys + } + }) +} diff --git a/store/store.go b/store/store.go index 02bbb11ca..dd49e0c97 100644 --- a/store/store.go +++ b/store/store.go @@ -501,6 +501,7 @@ type PluginStore interface { SaveOrUpdate(keyVal *model.PluginKeyValue) StoreChannel Get(pluginId, key string) StoreChannel Delete(pluginId, key string) StoreChannel + List(pluginId string, page, perPage int) StoreChannel } type RoleStore interface { diff --git a/store/storetest/mocks/PluginStore.go b/store/storetest/mocks/PluginStore.go index b6f161a86..9c4a40032 100644 --- a/store/storetest/mocks/PluginStore.go +++ b/store/storetest/mocks/PluginStore.go @@ -45,6 +45,22 @@ func (_m *PluginStore) Get(pluginId string, key string) store.StoreChannel { return r0 } +// List provides a mock function with given fields: pluginId, page, perPage +func (_m *PluginStore) List(pluginId string, page int, perPage int) store.StoreChannel { + ret := _m.Called(pluginId, page, perPage) + + var r0 store.StoreChannel + if rf, ok := ret.Get(0).(func(string, int, int) store.StoreChannel); ok { + r0 = rf(pluginId, page, perPage) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(store.StoreChannel) + } + } + + return r0 +} + // SaveOrUpdate provides a mock function with given fields: keyVal func (_m *PluginStore) SaveOrUpdate(keyVal *model.PluginKeyValue) store.StoreChannel { ret := _m.Called(keyVal) |