diff options
author | Daniel Schalla <daniel@schalla.me> | 2018-10-10 19:55:12 +0200 |
---|---|---|
committer | Christopher Speller <crspeller@gmail.com> | 2018-10-10 10:55:12 -0700 |
commit | c36e85c9126b921cf00e578ac70c1f1ee0153abd (patch) | |
tree | 86bfea62ec6a1ce0edc548db4a87851c41e30b88 /app | |
parent | bd04d7f75698c7b68434199208dc469021b823c2 (diff) | |
download | chat-c36e85c9126b921cf00e578ac70c1f1ee0153abd.tar.gz chat-c36e85c9126b921cf00e578ac70c1f1ee0153abd.tar.bz2 chat-c36e85c9126b921cf00e578ac70c1f1ee0153abd.zip |
DeleteAll for KV (#9431)
Expire K/V Values
Regenerate Code
pathfix
Update Expiry on Update
Check for Exit Signal
gofmt
Rewrote Go Routine
Remove tempoarily cleanup loop
fix expiretime
TEST: Expired Watchdog as GoRoutine
Check if Srv is nil
Use Scheduler/Worker for Expired Key CleanUp
add license
fix scheduler job type; DoJob Restructuring
Remove unused imports and constants
move db migration from 5.4 to 5.5
Diffstat (limited to 'app')
-rw-r--r-- | app/plugin.go | 1 | ||||
-rw-r--r-- | app/plugin_api.go | 8 | ||||
-rw-r--r-- | app/plugin_key_value_store.go | 35 |
3 files changed, 44 insertions, 0 deletions
diff --git a/app/plugin.go b/app/plugin.go index 51e67e2bf..2c18c6cec 100644 --- a/app/plugin.go +++ b/app/plugin.go @@ -146,6 +146,7 @@ func (a *App) InitPlugins(pluginDir, webappPluginDir string) { }) a.SyncPluginsActiveState() + } func (a *App) ShutDownPlugins() { diff --git a/app/plugin_api.go b/app/plugin_api.go index 8def80180..70b3d60fe 100644 --- a/app/plugin_api.go +++ b/app/plugin_api.go @@ -331,6 +331,10 @@ func (api *PluginAPI) KVSet(key string, value []byte) *model.AppError { return api.app.SetPluginKey(api.id, key, value) } +func (api *PluginAPI) KVSetWithExpiry(key string, value []byte, expireInSeconds int64) *model.AppError { + return api.app.SetPluginKeyWithExpiry(api.id, key, value, expireInSeconds) +} + func (api *PluginAPI) KVGet(key string) ([]byte, *model.AppError) { return api.app.GetPluginKey(api.id, key) } @@ -339,6 +343,10 @@ func (api *PluginAPI) KVDelete(key string) *model.AppError { return api.app.DeletePluginKey(api.id, key) } +func (api *PluginAPI) KVDeleteAll() *model.AppError { + return api.app.DeleteAllKeysForPlugin(api.id) +} + func (api *PluginAPI) KVList(page, perPage int) ([]string, *model.AppError) { return api.app.ListPluginKeys(api.id, page, perPage) } diff --git a/app/plugin_key_value_store.go b/app/plugin_key_value_store.go index 8c3e1f18b..f0aed31f0 100644 --- a/app/plugin_key_value_store.go +++ b/app/plugin_key_value_store.go @@ -19,10 +19,20 @@ func getKeyHash(key string) string { } func (a *App) SetPluginKey(pluginId string, key string, value []byte) *model.AppError { + return a.SetPluginKeyWithExpiry(pluginId, key, value, 0) +} + +func (a *App) SetPluginKeyWithExpiry(pluginId string, key string, value []byte, expireInSeconds int64) *model.AppError { + + if expireInSeconds > 0 { + expireInSeconds = model.GetMillis() + (expireInSeconds * 1000) + } + kv := &model.PluginKeyValue{ PluginId: pluginId, Key: getKeyHash(key), Value: value, + ExpireAt: expireInSeconds, } result := <-a.Srv.Store.Plugin().SaveOrUpdate(kv) @@ -60,6 +70,31 @@ func (a *App) DeletePluginKey(pluginId string, key string) *model.AppError { return result.Err } +func (a *App) DeleteAllKeysForPlugin(pluginId string) *model.AppError { + result := <-a.Srv.Store.Plugin().DeleteAllForPlugin(pluginId) + + if result.Err != nil { + mlog.Error(result.Err.Error()) + } + + return result.Err +} + +func (a *App) DeleteAllExpiredPluginKeys() *model.AppError { + + if a.Srv == nil { + return nil + } + + result := <-a.Srv.Store.Plugin().DeleteAllExpired() + + if result.Err != nil { + mlog.Error(result.Err.Error()) + } + + return result.Err +} + func (a *App) ListPluginKeys(pluginId string, page, perPage int) ([]string, *model.AppError) { result := <-a.Srv.Store.Plugin().List(pluginId, page, perPage) |