1
0
Fork 0
mirror of synced 2024-10-04 03:54:37 +13:00

Promise.all for both counts (SQS and SQL).

This commit is contained in:
mike12345567 2024-06-19 13:39:00 +01:00
parent 0e5de7f16d
commit bc80841554
2 changed files with 17 additions and 13 deletions

View file

@ -81,12 +81,12 @@ export async function search(
paginate: paginateObj as PaginationJson,
includeSqlRelationships: IncludeRelationship.INCLUDE,
}
const requests: Promise<Row[] | number>[] = []
requests.push(handleRequest(Operation.READ, tableId, parameters))
const queries: Promise<Row[] | number>[] = []
queries.push(handleRequest(Operation.READ, tableId, parameters))
if (countRows) {
requests.push(handleRequest(Operation.COUNT, tableId, parameters))
queries.push(handleRequest(Operation.COUNT, tableId, parameters))
}
const responses = await Promise.all(requests)
const responses = await Promise.all(queries)
let rows = responses[0] as Row[]
const totalRows = responses[1] ? (responses[1] as number) : undefined

View file

@ -213,7 +213,19 @@ export async function search(
}
try {
const rows = await runSqlQuery(request, allTables)
const queries: Promise<Row[] | number>[] = []
queries.push(runSqlQuery(request, allTables))
if (options.countRows) {
// get the total count of rows
queries.push(
runSqlQuery(request, allTables, {
countTotalRows: true,
})
)
}
const responses = await Promise.all(queries)
let rows = responses[0] as Row[]
const totalRows = responses[1] ? (responses[1] as number) : undefined
// process from the format of tableId.column to expected format also
// make sure JSON columns corrected
@ -231,14 +243,6 @@ export async function search(
nextRow = processed.pop()
}
let totalRows: number | undefined
if (options.countRows) {
// get the total count of rows
totalRows = await runSqlQuery(request, allTables, {
countTotalRows: true,
})
}
// get the rows
let finalRows = await outputProcessing<Row[]>(table, processed, {
preserveLinks: true,