From a1995d4a15473d4a050c8d2c3d0cb9d6e06c509a Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Thu, 9 Jun 2016 12:13:16 -0700 Subject: [PATCH] fix(plugin-ids): Lookup plugin id if pkg is not loaded --- src/package-manager.coffee | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/package-manager.coffee b/src/package-manager.coffee index 18c98d47b..58ee13b6a 100644 --- a/src/package-manager.coffee +++ b/src/package-manager.coffee @@ -48,6 +48,7 @@ class PackageManager @packageDirPaths.push(path.join(configDirPath, "packages")) @loadedPackages = {} + @cachedPackagePluginIds = {} @packagesWithDatabaseObjects = [] @activePackages = {} @packageStates = {} @@ -56,9 +57,24 @@ class PackageManager @registerPackageActivator(this, ['nylas']) - pluginIdFor: (pluginName) => + pluginIdFor: (packageName) => env = NylasEnv.config.get("env") - return @loadedPackages[pluginName]?.metadata.appId?[env] + cacheKey = "#{packageName}:#{env}" + + if @cachedPackagePluginIds[cacheKey] is undefined + @cachedPackagePluginIds[cacheKey] = @_resolvePluginIdFor(packageName, env) + return @cachedPackagePluginIds[cacheKey] + + _resolvePluginIdFor: (packageName, env) => + metadata = @loadedPackages[packageName]?.metadata + + unless metadata + packagePath = @resolvePackagePath(packageName) + return null unless packagePath + metadata = Package.loadMetadata(packagePath) + + return metadata.appId[env] if metadata and metadata.appId instanceof Object + return null ### Section: Event Subscription