Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

performance optimization #4488

Closed
wants to merge 3 commits into from
Closed
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
13 changes: 7 additions & 6 deletions src/Adapters/Storage/Postgres/PostgresStorageAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -743,9 +743,11 @@ export class PostgresStorageAdapter implements StorageAdapter {
// ELSE: Table already exists, must have been created by a different request. Ignore the error.
}
yield t.tx('create-table-tx', tx => {
return tx.batch(relations.map(fieldName => {
return tx.none('CREATE TABLE IF NOT EXISTS $<joinTable:name> ("relatedId" varChar(120), "owningId" varChar(120), PRIMARY KEY("relatedId", "owningId") )', {joinTable: `_Join:${fieldName}:${className}`});
const queries = relations.map(fieldName => ({
query: 'CREATE TABLE IF NOT EXISTS $<joinTable:name> ("relatedId" varChar(120), "owningId" varChar(120), PRIMARY KEY("relatedId", "owningId"))',
values: {joinTable: `_Join:${fieldName}:${className}`}
}));
return tx.none(self._pgp.helpers.concat(queries));
});
});
}
Expand Down Expand Up @@ -884,7 +886,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
const self = this;
return this._client.task('get-all-classes', function * (t) {
yield self._ensureSchemaCollectionExists(t);
return yield t.map('SELECT * FROM "_SCHEMA"', null, row => toParseSchema({ className: row.className, ...row.schema }));
return yield t.map('SELECT * FROM "_SCHEMA"', [], row => toParseSchema({ className: row.className, ...row.schema }));
});
}

Expand Down Expand Up @@ -1642,9 +1644,8 @@ export class PostgresStorageAdapter implements StorageAdapter {
}

createIndexes(className: string, indexes: any, conn: ?any): Promise<void> {
return (conn || this._client).tx(t => t.batch(indexes.map(i => {
return t.none('CREATE INDEX $1:name ON $2:name ($3:name)', [i.name, className, i.key]);
})));
const queries = indexes.map(i => ({query: 'CREATE INDEX $1:name ON $2:name ($3:name)', values: [i.name, className, i.key]}));
return (conn || this._client).tx(t => t.none(this._pgp.helpers.concat(queries)));
}

createIndexesIfNeeded(className: string, fieldName: string, type: any, conn: ?any): Promise<void> {
Expand Down