Chore: Propagate context for plugin settings (#41166)

Ref #36734
This commit is contained in:
Marcus Efraimsson
2021-11-02 13:42:55 +01:00
committed by GitHub
parent 1a89d97fed
commit f6be78b5ae
10 changed files with 58 additions and 49 deletions
+4 -4
View File
@@ -48,7 +48,7 @@ type Provider struct {
// Get allows getting plugin context by its ID. If datasourceUID is not empty string
// then PluginContext.DataSourceInstanceSettings will be resolved and appended to
// returned context.
func (p *Provider) Get(pluginID string, datasourceUID string, user *models.SignedInUser, skipCache bool) (backend.PluginContext, bool, error) {
func (p *Provider) Get(ctx context.Context, pluginID string, datasourceUID string, user *models.SignedInUser, skipCache bool) (backend.PluginContext, bool, error) {
pc := backend.PluginContext{}
plugin := p.pluginStore.Plugin(pluginID)
if plugin == nil {
@@ -59,7 +59,7 @@ func (p *Provider) Get(pluginID string, datasourceUID string, user *models.Signe
decryptedSecureJSONData := map[string]string{}
var updated time.Time
ps, err := p.getCachedPluginSettings(pluginID, user)
ps, err := p.getCachedPluginSettings(ctx, pluginID, user)
if err != nil {
// models.ErrPluginSettingNotFound is expected if there's no row found for plugin setting in database (if non-app plugin).
// If it's not this expected error something is wrong with cache or database and we return the error to the client.
@@ -104,7 +104,7 @@ func (p *Provider) Get(pluginID string, datasourceUID string, user *models.Signe
const pluginSettingsCacheTTL = 5 * time.Second
const pluginSettingsCachePrefix = "plugin-setting-"
func (p *Provider) getCachedPluginSettings(pluginID string, user *models.SignedInUser) (*models.PluginSetting, error) {
func (p *Provider) getCachedPluginSettings(ctx context.Context, pluginID string, user *models.SignedInUser) (*models.PluginSetting, error) {
cacheKey := pluginSettingsCachePrefix + pluginID
if cached, found := p.CacheService.Get(cacheKey); found {
@@ -115,7 +115,7 @@ func (p *Provider) getCachedPluginSettings(pluginID string, user *models.SignedI
}
query := models.GetPluginSettingByIdQuery{PluginId: pluginID, OrgId: user.OrgId}
if err := p.Bus.Dispatch(&query); err != nil {
if err := p.Bus.DispatchCtx(ctx, &query); err != nil {
return nil, err
}