Update caching logic to avoid map access
Signed-off-by: Derek McGowan <derek@mcg.dev>
This commit is contained in:
		| @@ -177,25 +177,6 @@ func checkUnique(r *Registration) error { | |||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
| // AreRegisteredPluginsInitialized returns all registered plugins are initialized |  | ||||||
| func AreRegisteredPluginsInitialized(plugins *Set) bool { |  | ||||||
| 	if len(register.r) != len(plugins.ordered) { |  | ||||||
| 		return false |  | ||||||
| 	} |  | ||||||
| 	for _, reg := range register.r { |  | ||||||
| 		byID, typeok := plugins.byTypeAndID[reg.Type] |  | ||||||
| 		if !typeok { |  | ||||||
| 			return false |  | ||||||
| 		} |  | ||||||
|  |  | ||||||
| 		if _, ok := byID[reg.ID]; !ok { |  | ||||||
| 			return false |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	return true |  | ||||||
| } |  | ||||||
|  |  | ||||||
| // DisableFilter filters out disabled plugins | // DisableFilter filters out disabled plugins | ||||||
| type DisableFilter func(r *Registration) bool | type DisableFilter func(r *Registration) bool | ||||||
|  |  | ||||||
|   | |||||||
| @@ -52,10 +52,10 @@ func init() { | |||||||
|  |  | ||||||
| // Local is a local implementation of the introspection service | // Local is a local implementation of the introspection service | ||||||
| type Local struct { | type Local struct { | ||||||
| 	mu        sync.Mutex | 	mu          sync.Mutex | ||||||
| 	root      string | 	root        string | ||||||
| 	plugins   *plugin.Set | 	plugins     *plugin.Set | ||||||
| 	pluginsPB []api.Plugin | 	pluginCache []api.Plugin | ||||||
| } | } | ||||||
|  |  | ||||||
| var _ = (api.IntrospectionClient)(&Local{}) | var _ = (api.IntrospectionClient)(&Local{}) | ||||||
| @@ -90,16 +90,13 @@ func (l *Local) Plugins(ctx context.Context, req *api.PluginsRequest, _ ...grpc. | |||||||
| } | } | ||||||
|  |  | ||||||
| func (l *Local) getPlugins() []api.Plugin { | func (l *Local) getPlugins() []api.Plugin { | ||||||
| 	if !plugin.AreRegisteredPluginsInitialized(l.plugins) { |  | ||||||
| 		return pluginsToPB(l.plugins.GetAll()) |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	l.mu.Lock() | 	l.mu.Lock() | ||||||
| 	defer l.mu.Unlock() | 	defer l.mu.Unlock() | ||||||
| 	if l.pluginsPB == nil { | 	plugins := l.plugins.GetAll() | ||||||
| 		l.pluginsPB = pluginsToPB(l.plugins.GetAll()) | 	if l.pluginCache == nil || len(plugins) != len(l.pluginCache) { | ||||||
|  | 		l.pluginCache = pluginsToPB(plugins) | ||||||
| 	} | 	} | ||||||
| 	return l.pluginsPB | 	return l.pluginCache | ||||||
| } | } | ||||||
|  |  | ||||||
| // Server returns the local server information | // Server returns the local server information | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Derek McGowan
					Derek McGowan