From 78bb674a71334bc6c26bcfa4acd8caf7d9d6f785 Mon Sep 17 00:00:00 2001 From: zcurrent <84637714+zcurrent@users.noreply.github.com> Date: Thu, 20 Apr 2023 22:01:53 +0000 Subject: [PATCH] - Updated queryWithPaging to make one request per second to avoid concurrency issues.\n- Created changeset Signed-off-by: zcurrent Signed-off-by: zcurrent <84637714+zcurrent@users.noreply.github.com> --- .changeset/olive-turkeys-switch.md | 5 +++++ plugins/catalog-backend-module-github/src/lib/github.ts | 2 ++ 2 files changed, 7 insertions(+) create mode 100644 .changeset/olive-turkeys-switch.md diff --git a/.changeset/olive-turkeys-switch.md b/.changeset/olive-turkeys-switch.md new file mode 100644 index 0000000000..d208f3b197 --- /dev/null +++ b/.changeset/olive-turkeys-switch.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-backend-module-github': patch +--- + +Fixed bug in queryWithPaging that caused secondary rate limit errors in GitHub with organizations having more than 1000 repositories. This change makes one request per second to avoid concurrency issues. diff --git a/plugins/catalog-backend-module-github/src/lib/github.ts b/plugins/catalog-backend-module-github/src/lib/github.ts index 39501e89bc..d0b629092a 100644 --- a/plugins/catalog-backend-module-github/src/lib/github.ts +++ b/plugins/catalog-backend-module-github/src/lib/github.ts @@ -545,6 +545,7 @@ export async function queryWithPaging< variables: Variables, ): Promise { const result: OutputType[] = []; + const sleep = (ms: number) => new Promise(r => setTimeout(r, ms)); let cursor: string | undefined = undefined; for (let j = 0; j < 1000 /* just for sanity */; ++j) { @@ -573,6 +574,7 @@ export async function queryWithPaging< if (!conn.pageInfo.hasNextPage) { break; } else { + await sleep(1000); cursor = conn.pageInfo.endCursor; } }