Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions packages/orb-sync-lib/src/database/postgres.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ export class PostgresClient {
pool: pg.Pool;

constructor(private config: PostgresConfig) {
this.pool = new pg.Pool({ connectionString: config.databaseUrl, max: 25, keepAlive: true });
this.pool = new pg.Pool({
connectionString: config.databaseUrl,
max: 25,
keepAlive: true,
application_name: 'orb-sync-engine',
});
}

async upsertMany<
Expand Down Expand Up @@ -51,12 +56,7 @@ export class PostgresClient {
T extends {
[Key: string]: any; // eslint-disable-line @typescript-eslint/no-explicit-any
},
>(
entries: T[],
table: string,
tableSchema: JsonSchema,
syncTimestamp: string
): Promise<T[]> {
>(entries: T[], table: string, tableSchema: JsonSchema, syncTimestamp: string): Promise<T[]> {
if (!entries.length) return [];

// Max 5 in parallel to avoid exhausting connection pool
Expand All @@ -72,12 +72,8 @@ export class PostgresClient {
const cleansed = this.cleanseArrayField(entry, tableSchema);
// Add last_synced_at to the cleansed data for SQL parameter binding
cleansed.last_synced_at = syncTimestamp;

const upsertSql = this.constructUpsertWithTimestampProtectionSql(
this.config.schema,
table,
tableSchema
);

const upsertSql = this.constructUpsertWithTimestampProtectionSql(this.config.schema, table, tableSchema);

const prepared = sql(upsertSql, {
useNullForMissing: true,
Expand Down