Skip to content

Commit

Permalink
Reduce the number of calls to the catalog API endpoint
Browse files Browse the repository at this point in the history
Instead, get the list of existing locations only once from the API
  • Loading branch information
rm3l committed Jun 14, 2024
1 parent 68afa55 commit 25ad787
Show file tree
Hide file tree
Showing 4 changed files with 290 additions and 231 deletions.
16 changes: 16 additions & 0 deletions plugins/bulk-import-backend/src/helpers/catalogInfoGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,20 @@ ${jsYaml.dump(generatedEntity.entity)}`,
getCatalogUrl(repoUrl: string, defaultBranch: string = 'main'): string {
return `${repoUrl}/blob/${defaultBranch}/catalog-info.yaml`;
}

async listCatalogUrlLocations(): Promise<string[]> {
const response = await fetch(
`${await this.discovery.getBaseUrl('catalog')}/locations`,
{
headers: {
'Accept': 'application/json',
},
method: 'GET',
},
);
const locations = (await response.json()) as {data: {id: string, target: string, type: string}}[];
return locations
.filter(location => location.data.type === 'url')
.map(location => location.data.target);
}
}
Loading

0 comments on commit 25ad787

Please sign in to comment.