Fix plugin cache initialisation (#1475)

This commit is contained in:
WithoutPants 2021-06-03 11:00:17 +10:00 committed by GitHub
parent c98cc73f33
commit 508f7b84f2
Failed to retrieve any key attached to the committer's account
3 changed files with 22 additions and 33 deletions

View File

@ -40,7 +40,7 @@ func (r *mutationResolver) RunPluginTask(ctx context.Context, pluginID string, t
}
func (r *mutationResolver) ReloadPlugins(ctx context.Context) (bool, error) {
err := manager.GetInstance().PluginCache.ReloadPlugins()
err := manager.GetInstance().PluginCache.LoadPlugins()
if err != nil {
logger.Errorf("Error reading plugin configs: %s", err.Error())
}

View File

@ -69,6 +69,7 @@ func Initialize() *singleton {
Config: cfg,
JobManager: job.NewManager(),
DownloadStore: NewDownloadStore(),
PluginCache: plugin.NewCache(cfg),
TxnManager: sqlite.NewTransactionManager(),
@ -170,17 +171,6 @@ func initLog() {
logger.Init(config.GetLogFile(), config.GetLogOut(), config.GetLogLevel())
}
func initPluginCache() *plugin.Cache {
config := config.GetInstance()
ret, err := plugin.NewCache(config.GetPluginsPath())
if err != nil {
logger.Errorf("Error reading plugin configs: %s", err.Error())
}
return ret
}
// PostInit initialises the paths, caches and txnManager after the initial
// configuration has been set. Should only be called if the configuration
// is valid.
@ -188,11 +178,14 @@ func (s *singleton) PostInit() error {
s.Config.SetInitialConfig()
s.Paths = paths.NewPaths(s.Config.GetGeneratedPath())
s.PluginCache = initPluginCache()
s.ScraperCache = instance.initScraperCache()
s.RefreshConfig()
if err := s.PluginCache.LoadPlugins(); err != nil {
logger.Errorf("Error reading plugin configs: %s", err.Error())
}
s.ScraperCache = instance.initScraperCache()
// clear the downloads and tmp directories
// #1021 - only clear these directories if the generated folder is non-empty
if s.Config.GetGeneratedPath() != "" {

View File

@ -14,44 +14,40 @@ import (
"path/filepath"
"github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/manager/config"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/plugin/common"
)
// Cache stores plugin details.
type Cache struct {
path string
config *config.Instance
plugins []Config
gqlHandler http.HandlerFunc
}
// NewCache returns a new Cache loading plugin configurations
// from the provided plugin path. It returns an new instance and an error
// if the plugin directory could not be loaded.
// NewCache returns a new Cache.
//
// Plugins configurations are loaded from yml files in the provided plugin
// directory and any subdirectories.
func NewCache(pluginPath string) (*Cache, error) {
plugins, err := loadPlugins(pluginPath)
if err != nil {
return nil, err
}
// Plugins configurations are loaded from yml files in the plugin
// directory in the config and any subdirectories.
//
// Does not load plugins. Plugins will need to be
// loaded explicitly using ReloadPlugins.
func NewCache(config *config.Instance) *Cache {
return &Cache{
path: pluginPath,
plugins: plugins,
}, nil
config: config,
}
}
func (c *Cache) RegisterGQLHandler(handler http.HandlerFunc) {
c.gqlHandler = handler
}
// ReloadPlugins clears the plugin cache and reloads from the plugin path.
// LoadPlugins clears the plugin cache and loads from the plugin path.
// In the event of an error during loading, the cache will be left empty.
func (c *Cache) ReloadPlugins() error {
func (c *Cache) LoadPlugins() error {
c.plugins = nil
plugins, err := loadPlugins(c.path)
plugins, err := loadPlugins(c.config.GetPluginsPath())
if err != nil {
return err
}