From 7c33cf62df5dc49b422709ed8a6b7de207cfb00d Mon Sep 17 00:00:00 2001 From: Vitaly Tomilov Date: Mon, 25 Dec 2017 01:53:27 +0000 Subject: [PATCH] PostgreSQL performance optimization Performance-optimizing transactions to execute all non-result queries as a single operation. --- src/Adapters/Storage/Postgres/PostgresStorageAdapter.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js b/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js index 1cc61c2aae..8724aaa64c 100644 --- a/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js +++ b/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js @@ -802,7 +802,8 @@ export class PostgresStorageAdapter { return list.concat(joinTablesForSchema(schema.schema)); }, []); const classes = ['_SCHEMA', '_PushStatus', '_JobStatus', '_JobSchedule', '_Hooks', '_GlobalConfig', '_Audience', ...results.map(result => result.className), ...joins]; - return this._client.tx(t=>t.batch(classes.map(className=>t.none('DROP TABLE IF EXISTS $', {className})))); + const queries = classes.map(className => ({query: 'DROP TABLE IF EXISTS $', values: {className}})); + return this._client.tx(t => t.none(this._pgp.helpers.concat(queries))); }, error => { if (error.code === PostgresRelationDoesNotExistError) { // No _SCHEMA collection. Don't delete anything. @@ -1598,7 +1599,8 @@ export class PostgresStorageAdapter { } dropIndexes(className, indexes, conn) { - return (conn || this._client).tx(t => t.batch(indexes.map(i => t.none('DROP INDEX $1:name', i)))); + const queries = indexes.map(i => ({query: 'DROP INDEX $1:name', values: i})); + return (conn || this._client).tx(t => t.none(this._pgp.helpers.concat(queries))); } getIndexes(className) {