Merge pull request #4530 from annando/db-timestamp

Some more performance measuring for database stuff
2022.09-rc
Hypolite Petovan 2018-03-02 14:11:32 -05:00 zatwierdzone przez GitHub
commit 38e5e64532
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
1 zmienionych plików z 26 dodań i 6 usunięć

Wyświetl plik

@ -664,16 +664,24 @@ class dba {
* @return array current row * @return array current row
*/ */
public static function fetch($stmt) { public static function fetch($stmt) {
$a = get_app();
$stamp1 = microtime(true);
$columns = [];
if (!is_object($stmt)) { if (!is_object($stmt)) {
return false; return false;
} }
switch (self::$driver) { switch (self::$driver) {
case 'pdo': case 'pdo':
return $stmt->fetch(PDO::FETCH_ASSOC); $columns = $stmt->fetch(PDO::FETCH_ASSOC);
break;
case 'mysqli': case 'mysqli':
if (get_class($stmt) == 'mysqli_result') { if (get_class($stmt) == 'mysqli_result') {
return $stmt->fetch_assoc(); $columns = $stmt->fetch_assoc();
break;
} }
// This code works, but is slow // This code works, but is slow
@ -698,12 +706,14 @@ class dba {
$result = $stmt->result_metadata(); $result = $stmt->result_metadata();
$fields = $result->fetch_fields(); $fields = $result->fetch_fields();
$columns = [];
foreach ($cols_num AS $param => $col) { foreach ($cols_num AS $param => $col) {
$columns[$fields[$param]->name] = $col; $columns[$fields[$param]->name] = $col;
} }
return $columns;
} }
$a->save_timestamp($stamp1, 'database');
return $columns;
} }
/** /**
@ -1287,17 +1297,27 @@ class dba {
* @return boolean was the close successful? * @return boolean was the close successful?
*/ */
public static function close($stmt) { public static function close($stmt) {
$a = get_app();
$stamp1 = microtime(true);
if (!is_object($stmt)) { if (!is_object($stmt)) {
return false; return false;
} }
switch (self::$driver) { switch (self::$driver) {
case 'pdo': case 'pdo':
return $stmt->closeCursor(); $ret = $stmt->closeCursor();
break;
case 'mysqli': case 'mysqli':
$stmt->free_result(); $stmt->free_result();
return $stmt->close(); $ret = $stmt->close();
break;
} }
$a->save_timestamp($stamp1, 'database');
return $ret;
} }
} }