Skip to content

Commit 1af3e65

Browse files
authored
Revert "4.4 to 5.2 upmerge 2024-08-29" (joomla#43998)
1 parent b19b923 commit 1af3e65

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

tests/System/plugins/db.mjs

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ import postgres from 'postgres';
44
// Items cache which are added by an insert statement
55
let insertedItems = [];
66

7-
// Use of the PostgreSQL connection pool to limit the number of sessions, see
8-
// https://github.com/porsager/postgres?tab=readme-ov-file#connection-details
9-
let postgresConnectionPool = null;
10-
117
/**
128
* Does run the given query against the database from the configuration. It caches all inserted items.
139
*
@@ -33,20 +29,17 @@ function queryTestDB(joomlaQuery, config) {
3329
insertedItems.push(insertItem);
3430
}
3531

36-
// Do we use PostgreSQL?
32+
// Check if the DB is from postgres
3733
if (config.env.db_type === 'pgsql' || config.env.db_type === 'PostgreSQL (PDO)') {
38-
39-
if (postgresConnectionPool === null) {
40-
// Initialisation on the first call
41-
postgresConnectionPool = postgres({
42-
host: config.env.db_host,
43-
port: config.env.db_port,
44-
database: config.env.db_name,
45-
username: config.env.db_user,
46-
password: config.env.db_password,
47-
max: 10, // Use only this (unchanged default) maximum number of connections in the pool
48-
});
49-
}
34+
const connection = postgres({
35+
host: config.env.db_host,
36+
port: config.env.db_port,
37+
database: config.env.db_name,
38+
username: config.env.db_user,
39+
password: config.env.db_password,
40+
idle_timeout: 1,
41+
max_lifetime: 1,
42+
});
5043

5144
// Postgres delivers the data direct as result of the insert query
5245
if (insertItem) {
@@ -56,7 +49,7 @@ function queryTestDB(joomlaQuery, config) {
5649
// Postgres needs double quotes
5750
query = query.replaceAll('`', '"');
5851

59-
return postgresConnectionPool.unsafe(query).then((result) => {
52+
return connection.unsafe(query).then((result) => {
6053
// Select query should always return an array
6154
if (query.indexOf('SELECT') === 0 && !Array.isArray(result)) {
6255
return [result];
@@ -71,12 +64,12 @@ function queryTestDB(joomlaQuery, config) {
7164
insertItem.rows.push(result[0].id);
7265
}
7366

74-
// Normalize the object and return from PostgreSQL
67+
// Normalize the object
7568
return { insertId: result[0].id };
7669
});
7770
}
7871

79-
// Return a promise which runs the query for MariaDB / MySQL
72+
// Return a promise which runs the query
8073
return new Promise((resolve, reject) => {
8174
// Create the connection and connect
8275
const connection = mysql.createConnection({
@@ -101,7 +94,7 @@ function queryTestDB(joomlaQuery, config) {
10194
insertItem.rows.push(results.insertId);
10295
}
10396

104-
// Resolve the result from MariaDB / MySQL
97+
// Resolve the result
10598
return resolve(results);
10699
});
107100
});

0 commit comments

Comments
 (0)