Skip to content

Commit

Permalink
perf: try to improve the performance of transformQueryLog
Browse files Browse the repository at this point in the history
  • Loading branch information
anatawa12 committed Jan 15, 2025
1 parent 5f0f4bf commit 0da26c4
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions packages/backend/src/postgres.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ function highlightSql(sql: string) {
});
}

function truncateSql(sql: string) {
return sql.length > 100 ? `${sql.substring(0, 100)}...` : sql;
function truncateSql(sql: string): [string, boolean] {
return sql.length > 100 ? [`${sql.substring(0, 100)}`, true] : [sql, false];
}

function stringifyParameter(param: any) {
Expand All @@ -117,13 +117,16 @@ class MyCustomLogger implements Logger {
}

@bindThis
private transformQueryLog(sql: string) {
private transformQueryLog(sql: string): string {
let modded = sql;
let truncated: boolean = false;
if (!this.props.disableQueryTruncation) {
modded = truncateSql(modded);
[modded, truncated] = truncateSql(modded);
}

return highlightSql(modded);
modded = highlightSql(modded);
if (truncated) modded += '...';
return modded;
}

@bindThis
Expand Down

0 comments on commit 0da26c4

Please sign in to comment.