Skip to content

Commit

Permalink
more optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
ktalebian committed May 11, 2021
1 parent ebb1465 commit b0e0ea2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,9 @@ describe('CreateConfigurationScript', () => {

const result = await script(option);
expect(activeRelease).not.toHaveBeenCalled();
expect(getPlugin).toHaveBeenCalledTimes(3);
expect(getPlugin).toHaveBeenCalledTimes(2);
expect(getPlugin).toHaveBeenCalledWith(plugin1.sid);
expect(getVersion).toHaveBeenCalledTimes(3);
expect(getVersion).toHaveBeenCalledTimes(2);
expect(getVersion).toHaveBeenCalledWith(plugin1.unique_name, 'version1');
expect(getVersion).toHaveBeenCalledWith(plugin1.sid, pluginVersion1.sid);
expect(getLatestVersion).not.toHaveBeenCalled();
Expand Down Expand Up @@ -333,12 +333,12 @@ describe('CreateConfigurationScript', () => {

const result = await script(option);
expect(activeRelease).toHaveBeenCalledTimes(1);
expect(getPlugin).toHaveBeenCalledTimes(5);
expect(getPlugin).toHaveBeenCalledTimes(3);
expect(getPlugin).toHaveBeenCalledWith(configuredPlugin1.unique_name);
expect(getPlugin).not.toHaveBeenCalledWith(configuredPlugin2.unique_name);
expect(getPlugin).toHaveBeenCalledWith(configuredPlugin1.plugin_sid);
expect(getPlugin).toHaveBeenCalledWith(configuredPlugin2.plugin_sid);
expect(getVersion).toHaveBeenCalledTimes(5);
expect(getVersion).toHaveBeenCalledTimes(3);
expect(getVersion).toHaveBeenCalledWith(plugin1.unique_name, 'version1');
expect(getVersion).toHaveBeenCalledWith(plugin1.sid, pluginVersion1.sid);
expect(getVersion).not.toHaveBeenCalledWith(plugin2.unique_name, pluginVersion2.version);
Expand Down Expand Up @@ -504,12 +504,12 @@ describe('CreateConfigurationScript', () => {

const result = await script(option);
expect(activeRelease).not.toHaveBeenCalled();
expect(getPlugin).toHaveBeenCalledTimes(5);
expect(getPlugin).toHaveBeenCalledTimes(3);
expect(getPlugin).toHaveBeenCalledWith(configuredPlugin1.unique_name);
expect(getPlugin).not.toHaveBeenCalledWith(configuredPlugin2.unique_name);
expect(getPlugin).toHaveBeenCalledWith(configuredPlugin1.plugin_sid);
expect(getPlugin).toHaveBeenCalledWith(configuredPlugin2.plugin_sid);
expect(getVersion).toHaveBeenCalledTimes(5);
expect(getVersion).toHaveBeenCalledTimes(3);
expect(getVersion).toHaveBeenCalledWith(plugin1.unique_name, 'version1');
expect(getVersion).toHaveBeenCalledWith(plugin1.sid, pluginVersion1.sid);
expect(getVersion).not.toHaveBeenCalledWith(plugin2.unique_name, pluginVersion2.version);
Expand Down Expand Up @@ -585,10 +585,10 @@ describe('CreateConfigurationScript', () => {

const result = await script(option);
expect(activeRelease).toHaveBeenCalledTimes(1);
expect(getPlugin).toHaveBeenCalledTimes(3);
expect(getPlugin).toHaveBeenCalledTimes(2);
expect(getPlugin).toHaveBeenCalledWith(configuredPlugin1.unique_name);
expect(getPlugin).toHaveBeenCalledWith(configuredPlugin1.plugin_sid);
expect(getVersion).toHaveBeenCalledTimes(3);
expect(getVersion).toHaveBeenCalledTimes(2);
expect(getVersion).toHaveBeenCalledWith(plugin1.unique_name, 'version1');
expect(getVersion).toHaveBeenCalledWith(plugin1.sid, pluginVersion1.sid);
expect(getLatestVersion).not.toHaveBeenCalled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,22 +164,19 @@ export default function createConfiguration(
// Fetch installed plugins
const configuredPluginsPage = await configuredPluginClient.list(configuration.sid);
const installedPlugins: InstalledPlugin[] = await Promise.all(
configuredPluginsPage.plugins.map(async (installedPlugin) => {
const plugin = await pluginClient.get(installedPlugin.plugin_sid);
const version = await pluginVersionClient.get(installedPlugin.plugin_sid, installedPlugin.plugin_version_sid);

configuredPluginsPage.plugins.map(async (p) => {
return {
pluginSid: installedPlugin.plugin_sid,
pluginVersionSid: installedPlugin.plugin_version_sid,
name: installedPlugin.unique_name,
version: installedPlugin.version,
url: installedPlugin.plugin_url,
phase: installedPlugin.phase,
friendlyName: plugin.friendly_name,
description: plugin.description,
changelog: version.changelog,
isPrivate: installedPlugin.private,
isArchived: plugin.archived || version.archived,
pluginSid: p.plugin_sid,
pluginVersionSid: p.plugin_version_sid,
name: p.unique_name,
version: p.version,
url: p.plugin_url,
phase: p.phase,
friendlyName: p.friendly_name,
description: p.description,
changelog: p.changelog,
isPrivate: p.private,
isArchived: p.plugin_archived,
};
}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Script } from '.';
import { DescribeConfiguration, internalDescribeConfiguration } from './describeConfiguration';

interface OptionalResources {
release?: ReleaseResource;
activeRelease?: ReleaseResource;
}

Expand Down Expand Up @@ -44,7 +45,7 @@ export default function describeRelease(
return async (option: DescribeReleaseOption) => {
const resources = option.resources ? option.resources : ({} as OptionalResources);

const release = await releasesClient.get(option.sid);
const release = await (resources.release ? Promise.resolve(resources.release) : releasesClient.get(option.sid));
const active = await (resources.activeRelease ? Promise.resolve(resources.activeRelease) : releasesClient.active());

const configuration = await internalDescribeConfiguration(configurationClient, configuredPluginClient)(
Expand Down

0 comments on commit b0e0ea2

Please sign in to comment.