PR comments.

This commit is contained in:
mike12345567 2024-08-01 13:07:34 +01:00
parent 99e8ef58dd
commit 224d2a1953
2 changed files with 14 additions and 25 deletions

View File

@ -106,17 +106,12 @@ export async function search(
paginate: paginateObj as PaginationJson,
includeSqlRelationships: IncludeRelationship.INCLUDE,
}
const queries: [
Promise<ExternalReadRequestReturnType>,
Promise<number> | undefined
] = [handleRequest(Operation.READ, tableId, parameters), undefined]
if (countRows) {
queries[1] = handleRequest(Operation.COUNT, tableId, parameters)
}
const responses = await Promise.all(queries)
let rows = responses[0].rows
const rawResponseSize = responses[0].rawResponseSize
const totalRows = responses.length > 1 ? responses[1] : undefined
const [{ rows, rawResponseSize }, totalRows] = await Promise.all([
handleRequest(Operation.READ, tableId, parameters),
countRows
? handleRequest(Operation.COUNT, tableId, parameters)
: Promise.resolve(undefined),
])
let processed = await outputProcessing<Row[]>(table, rows, {
preserveLinks: true,

View File

@ -332,20 +332,14 @@ export async function search(
}
try {
const queries: Promise<Row[] | number>[] = []
queries.push(runSqlQuery(request, allTables, relationships))
if (options.countRows) {
// get the total count of rows
queries.push(
runSqlQuery(request, allTables, relationships, {
const [rows, totalRows] = await Promise.all([
runSqlQuery(request, allTables, relationships),
options.countRows
? runSqlQuery(request, allTables, relationships, {
countTotalRows: true,
})
)
}
const responses = await Promise.all(queries)
let rows = responses[0] as Row[]
const totalRows =
responses.length > 1 ? (responses[1] as number) : undefined
: Promise.resolve(undefined),
])
// process from the format of tableId.column to expected format also
// make sure JSON columns corrected