Promise.all for both counts (SQS and SQL).
This commit is contained in:
parent
0e5de7f16d
commit
bc80841554
|
@ -81,12 +81,12 @@ export async function search(
|
||||||
paginate: paginateObj as PaginationJson,
|
paginate: paginateObj as PaginationJson,
|
||||||
includeSqlRelationships: IncludeRelationship.INCLUDE,
|
includeSqlRelationships: IncludeRelationship.INCLUDE,
|
||||||
}
|
}
|
||||||
const requests: Promise<Row[] | number>[] = []
|
const queries: Promise<Row[] | number>[] = []
|
||||||
requests.push(handleRequest(Operation.READ, tableId, parameters))
|
queries.push(handleRequest(Operation.READ, tableId, parameters))
|
||||||
if (countRows) {
|
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[]
|
let rows = responses[0] as Row[]
|
||||||
const totalRows = responses[1] ? (responses[1] as number) : undefined
|
const totalRows = responses[1] ? (responses[1] as number) : undefined
|
||||||
|
|
||||||
|
|
|
@ -213,7 +213,19 @@ export async function search(
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
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
|
// process from the format of tableId.column to expected format also
|
||||||
// make sure JSON columns corrected
|
// make sure JSON columns corrected
|
||||||
|
@ -231,14 +243,6 @@ export async function search(
|
||||||
nextRow = processed.pop()
|
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
|
// get the rows
|
||||||
let finalRows = await outputProcessing<Row[]>(table, processed, {
|
let finalRows = await outputProcessing<Row[]>(table, processed, {
|
||||||
preserveLinks: true,
|
preserveLinks: true,
|
||||||
|
|
Loading…
Reference in New Issue