mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-25 14:17:31 +00:00
fix(db): run plugin SQL on a pool client of its own instead of patching the pool
Plugin statements on Postgres went over the extended query protocol through a marker parameter and a hook that replaced query() on every client of TREK's pool. That kept a plugin to one statement per round trip, but it changed TREK's own hot path for a concern only plugin data has. The plugin data store now checks a pg client out of the ORM's pool for each transaction, through MikroORM's getNativeClient, and runs the transaction on it directly. Every plugin write goes as a query with queryMode 'extended' and every read through a pg-cursor on that client, so Postgres parses exactly one statement either way. The settings the transaction makes are local, and before the client goes back to the pool the store drops temporary tables, cursors, listeners, session advisory locks and sequence state, or closes a client it cannot bring back to that state. The row cap, quota, time budget, untimed migrate, per-plugin queue, pool share and script commits are as before, and plugin args are still sent without NUL. The marker, the hook and its install in the Postgres driver are gone.
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
dropPluginSchema,
|
||||
PluginDataSlots,
|
||||
pluginDataSlots,
|
||||
poolClients,
|
||||
PostgresPluginDataStore,
|
||||
} from '../../../db/engine/postgres/plugin-data-store';
|
||||
import { DATABASE_ENGINE, DATABASE_SETTINGS } from '../../database/database-engine.module';
|
||||
@@ -52,8 +53,9 @@ export class SqlitePluginDataBackend implements PluginDataBackend {
|
||||
|
||||
/**
|
||||
* Each plugin's own schema in TREK's Postgres database
|
||||
* (`db/engine/postgres/plugin-data-store.ts`), reached through the ORM's
|
||||
* pool. The plugin's data directory is still created, for the files a plugin
|
||||
* (`db/engine/postgres/plugin-data-store.ts`). Each call checks a client
|
||||
* out of the ORM's pool for itself; erasing a plugin runs on the ORM's Kysely
|
||||
* client. The plugin's data directory is still created, for the files a plugin
|
||||
* keeps beside its database, and it is what marks a plugin uninstalled with
|
||||
* its data kept (the erasure queue reads it).
|
||||
*/
|
||||
@@ -70,7 +72,7 @@ export class PostgresPluginDataBackend implements PluginDataBackend {
|
||||
|
||||
open(pluginId: string): PluginDataStore {
|
||||
fs.mkdirSync(pluginDataDir(pluginId), { recursive: true });
|
||||
return new PostgresPluginDataStore(pluginId, this.client(), this.sharedSlots());
|
||||
return new PostgresPluginDataStore(pluginId, poolClients(this.orm.em.getConnection()), this.sharedSlots());
|
||||
}
|
||||
|
||||
async erase(pluginId: string): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user