Skip to content

Commit

Permalink
perf: improve SapQueryRunner performance (#10198)
Browse files Browse the repository at this point in the history
Use async API exposed by SAP driver

Co-authored-by: Lukasz Otczyk <lukasz.otczyk@nexontis.com>
  • Loading branch information
lotczyk and Lukasz Otczyk authored Dec 29, 2023
1 parent bafcd17 commit f6b87e3
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/driver/sap/SapQueryRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,24 @@ export class SapQueryRunner extends BaseQueryRunner implements QueryRunner {
const queryStartTime = +new Date()
const isInsertQuery = query.substr(0, 11) === "INSERT INTO"

statement = databaseConnection.prepare(query)
if (parameters?.some(Array.isArray)) {
statement = await promisify(
databaseConnection.prepare.bind(databaseConnection),
)(query)
}

const raw = await new Promise<any>((ok, fail) => {
statement.exec(parameters, (err: any, raw: any) =>
err
? fail(new QueryFailedError(query, parameters, err))
: ok(raw),
)
})
let raw: any
try {
raw = statement
? await promisify(statement.exec.bind(statement))(
parameters,
)
: await promisify(
databaseConnection.exec.bind(databaseConnection),
)(query, parameters, {})
} catch (err) {
throw new QueryFailedError(query, parameters, err)
}

// log slow queries if maxQueryExecution time is set
const maxQueryExecutionTime =
Expand Down

0 comments on commit f6b87e3

Please sign in to comment.