diff --git a/.changeset/beige-chairs-repair.md b/.changeset/beige-chairs-repair.md new file mode 100644 index 0000000000..20cad7be6e --- /dev/null +++ b/.changeset/beige-chairs-repair.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-backend-module-bitbucket-cloud': patch +--- + +Refresh (potentially) updated catalog files on `repo:push` more efficiently. diff --git a/plugins/catalog-backend-module-bitbucket-cloud/package.json b/plugins/catalog-backend-module-bitbucket-cloud/package.json index f4d542f843..f58f3eec56 100644 --- a/plugins/catalog-backend-module-bitbucket-cloud/package.json +++ b/plugins/catalog-backend-module-bitbucket-cloud/package.json @@ -45,7 +45,6 @@ "@backstage/plugin-catalog-common": "workspace:^", "@backstage/plugin-catalog-node": "workspace:^", "@backstage/plugin-events-node": "workspace:^", - "p-limit": "^3.1.0", "uuid": "^8.0.0", "winston": "^3.2.1" }, diff --git a/plugins/catalog-backend-module-bitbucket-cloud/src/BitbucketCloudEntityProvider.test.ts b/plugins/catalog-backend-module-bitbucket-cloud/src/BitbucketCloudEntityProvider.test.ts index 2856a26a13..367e95b99b 100644 --- a/plugins/catalog-backend-module-bitbucket-cloud/src/BitbucketCloudEntityProvider.test.ts +++ b/plugins/catalog-backend-module-bitbucket-cloud/src/BitbucketCloudEntityProvider.test.ts @@ -22,11 +22,7 @@ import { } from '@backstage/backend-tasks'; import { setupRequestMockHandlers } from '@backstage/backend-test-utils'; import { CatalogApi } from '@backstage/catalog-client'; -import { - Entity, - LocationEntity, - stringifyEntityRef, -} from '@backstage/catalog-model'; +import { Entity, LocationEntity } from '@backstage/catalog-model'; import { ConfigReader } from '@backstage/config'; import { EntityProviderConnection, @@ -458,7 +454,6 @@ describe('BitbucketCloudEntityProvider', () => { items: [keptModule, removedModule], }; }, - refreshEntity: jest.fn(), }; const provider = BitbucketCloudEntityProvider.fromConfig(defaultConfig, { catalogApi: catalogApi as any as CatalogApi, @@ -557,11 +552,12 @@ describe('BitbucketCloudEntityProvider', () => { }, ]; - expect(catalogApi.refreshEntity).toHaveBeenCalledTimes(1); - expect(catalogApi.refreshEntity).toHaveBeenCalledWith( - stringifyEntityRef(keptModule), - { token: 'fake-token' }, - ); + expect(entityProviderConnection.refresh).toHaveBeenCalledTimes(1); + expect(entityProviderConnection.refresh).toHaveBeenCalledWith({ + keys: [ + 'url:https://bitbucket.org/test-ws/test-repo/src/main/kept-module/catalog-custom.yaml', + ], + }); expect(entityProviderConnection.applyMutation).toHaveBeenCalledTimes(1); expect(entityProviderConnection.applyMutation).toHaveBeenCalledWith({ type: 'delta', diff --git a/plugins/catalog-backend-module-bitbucket-cloud/src/BitbucketCloudEntityProvider.ts b/plugins/catalog-backend-module-bitbucket-cloud/src/BitbucketCloudEntityProvider.ts index 33b92589eb..83b6f447f2 100644 --- a/plugins/catalog-backend-module-bitbucket-cloud/src/BitbucketCloudEntityProvider.ts +++ b/plugins/catalog-backend-module-bitbucket-cloud/src/BitbucketCloudEntityProvider.ts @@ -17,11 +17,7 @@ import { TokenManager } from '@backstage/backend-common'; import { PluginTaskScheduler, TaskRunner } from '@backstage/backend-tasks'; import { CatalogApi } from '@backstage/catalog-client'; -import { - Entity, - LocationEntity, - stringifyEntityRef, -} from '@backstage/catalog-model'; +import { LocationEntity } from '@backstage/catalog-model'; import { Config } from '@backstage/config'; import { BitbucketCloudIntegration, @@ -44,7 +40,6 @@ import { BitbucketCloudEntityProviderConfig, readProviderConfigs, } from './BitbucketCloudEntityProviderConfig'; -import limiterFactory from 'p-limit'; import * as uuid from 'uuid'; import { Logger } from 'winston'; @@ -273,9 +268,7 @@ export class BitbucketCloudEntityProvider ), ); - const limiter = limiterFactory(10); - - const stillExisting: Entity[] = []; + const stillExisting: LocationEntity[] = []; const removed: DeferredEntity[] = []; existing.forEach(item => { if (targets.find(value => value.fileUrl === item.spec.target)) { @@ -288,22 +281,20 @@ export class BitbucketCloudEntityProvider } }); - const promises: Promise[] = stillExisting.map(entity => - limiter(async () => - this.catalogApi!.refreshEntity(stringifyEntityRef(entity), { token }), - ), - ); + const promises: Promise[] = [ + this.connection.refresh({ + keys: stillExisting.map(entity => `url:${entity.spec.target}`), + }), + ]; if (added.length > 0 || removed.length > 0) { const connection = this.connection; promises.push( - limiter(async () => - connection.applyMutation({ - type: 'delta', - added: added, - removed: removed, - }), - ), + connection.applyMutation({ + type: 'delta', + added: added, + removed: removed, + }), ); } diff --git a/yarn.lock b/yarn.lock index eea278d3b3..636a2c6823 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4485,7 +4485,6 @@ __metadata: "@backstage/plugin-events-node": "workspace:^" luxon: ^3.0.0 msw: ^0.49.0 - p-limit: ^3.1.0 uuid: ^8.0.0 winston: ^3.2.1 languageName: unknown