From c36e85c9126b921cf00e578ac70c1f1ee0153abd Mon Sep 17 00:00:00 2001 From: Daniel Schalla Date: Wed, 10 Oct 2018 19:55:12 +0200 Subject: 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 --- app/plugin_key_value_store.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'app/plugin_key_value_store.go') 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) -- cgit v1.2.3-1-g7c22