Skip to content

Commit 0e68691

Browse files
vitaly-tflovilmart
authored andcommitted
Better connection use in setClassLevelPermissions (#4460)
Method `setClassLevelPermissions` should use `.task` to share the connection for the two consecutive operations. It doesn't need a transaction, because the first operation does not need to roll back when the second one fails.
1 parent e0e706c commit 0e68691

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/Adapters/Storage/Postgres/PostgresStorageAdapter.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -612,9 +612,11 @@ export class PostgresStorageAdapter implements StorageAdapter {
612612
}
613613

614614
setClassLevelPermissions(className: string, CLPs: any) {
615-
return this._ensureSchemaCollectionExists().then(() => {
616-
const values = [className, 'schema', 'classLevelPermissions', JSON.stringify(CLPs)]
617-
return this._client.none(`UPDATE "_SCHEMA" SET $2:name = json_object_set_key($2:name, $3::text, $4::jsonb) WHERE "className"=$1 `, values);
615+
const self = this;
616+
return this._client.task('set-class-level-permissions', function * (t) {
617+
yield self._ensureSchemaCollectionExists(t);
618+
const values = [className, 'schema', 'classLevelPermissions', JSON.stringify(CLPs)];
619+
yield t.none(`UPDATE "_SCHEMA" SET $2:name = json_object_set_key($2:name, $3::text, $4::jsonb) WHERE "className"=$1`, values);
618620
});
619621
}
620622

0 commit comments

Comments
 (0)