catalog-backend: better concurrency and more eager response writing
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-catalog-backend': patch
|
||||
---
|
||||
|
||||
Improved concurrency of the `entities` endpoint when using the streamed query mode behind the `catalog.disableRelationsCompatibility` flag.
|
||||
@@ -181,6 +181,7 @@ export async function createRouter(
|
||||
let cursor: Cursor | undefined;
|
||||
|
||||
try {
|
||||
let currentWrite: Promise<boolean> | undefined = undefined;
|
||||
do {
|
||||
const result = await entitiesCatalog.queryEntities(
|
||||
!cursor
|
||||
@@ -195,15 +196,21 @@ export async function createRouter(
|
||||
: { credentials, fields, limit, cursor },
|
||||
);
|
||||
|
||||
// Wait for previous write to complete
|
||||
if (await currentWrite) {
|
||||
return; // Client closed connection
|
||||
}
|
||||
|
||||
if (result.items.entities.length) {
|
||||
if (await responseStream.send(result.items)) {
|
||||
return; // Client closed connection
|
||||
}
|
||||
currentWrite = responseStream.send(result.items);
|
||||
}
|
||||
|
||||
cursor = result.pageInfo?.nextCursor;
|
||||
} while (cursor);
|
||||
|
||||
// Wait for last write to complete
|
||||
await currentWrite;
|
||||
|
||||
responseStream.complete();
|
||||
} finally {
|
||||
responseStream.close();
|
||||
|
||||
Reference in New Issue
Block a user