Skip to content

Commit 820ae2b

Browse files
authored
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 a868bed commit 820ae2b

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
@@ -605,9 +605,11 @@ export class PostgresStorageAdapter {
605605
}
606606

607607
setClassLevelPermissions(className, CLPs) {
608-
return this._ensureSchemaCollectionExists().then(() => {
609-
const values = [className, 'schema', 'classLevelPermissions', JSON.stringify(CLPs)]
610-
return this._client.none(`UPDATE "_SCHEMA" SET $2:name = json_object_set_key($2:name, $3::text, $4::jsonb) WHERE "className"=$1 `, values);
608+
const self = this;
609+
return this._client.task('set-class-level-permissions', function * (t) {
610+
yield self._ensureSchemaCollectionExists(t);
611+
const values = [className, 'schema', 'classLevelPermissions', JSON.stringify(CLPs)];
612+
yield t.none(`UPDATE "_SCHEMA" SET $2:name = json_object_set_key($2:name, $3::text, $4::jsonb) WHERE "className"=$1`, values);
611613
});
612614
}
613615

0 commit comments

Comments
 (0)