Use the Index DbStatementCache implementation.

This commit is contained in:
flash 2023-07-22 14:00:51 +00:00
parent baefea88df
commit 42d893fc18
8 changed files with 7 additions and 47 deletions

View file

@ -3,10 +3,10 @@ namespace Misuzu\AuditLog;
use InvalidArgumentException;
use RuntimeException;
use Index\Data\DbStatementCache;
use Index\Data\IDbConnection;
use Index\Data\IDbResult;
use Index\Net\IPAddress;
use Misuzu\DbStatementCache;
use Misuzu\Pagination;
use Misuzu\Users\User;

View file

@ -4,10 +4,10 @@ namespace Misuzu\Changelog;
use InvalidArgumentException;
use RuntimeException;
use Index\DateTime;
use Index\Data\DbStatementCache;
use Index\Data\DbTools;
use Index\Data\IDbConnection;
use Index\Data\IDbResult;
use Misuzu\DbStatementCache;
use Misuzu\Pagination;
use Misuzu\Users\User;

View file

@ -3,9 +3,9 @@ namespace Misuzu\Comments;
use InvalidArgumentException;
use RuntimeException;
use Index\Data\DbStatementCache;
use Index\Data\IDbConnection;
use Index\Data\IDbResult;
use Misuzu\DbStatementCache;
use Misuzu\Pagination;
use Misuzu\Users\User;

View file

@ -4,11 +4,11 @@ namespace Misuzu\Config;
use RuntimeException;
use InvalidArgumentException;
use Index\Data\DataException;
use Index\Data\DbStatementCache;
use Index\Data\DbTools;
use Index\Data\IDbConnection;
use Index\Data\IDbStatement;
use Index\Data\IDbResult;
use Misuzu\DbStatementCache;
use Misuzu\Pagination;
class DbConfig implements IConfig {

View file

@ -1,40 +0,0 @@
<?php
namespace Misuzu;
use Index\Data\IDbConnection;
use Index\Data\IDbStatement;
class DbStatementCache {
private IDbConnection $dbConn;
private array $stmts = [];
public function __construct(IDbConnection $dbConn) {
$this->dbConn = $dbConn;
}
private static function hash(string $query): string {
return hash('xxh3', $query, true);
}
public function get(string $query): IDbStatement {
$hash = self::hash($query);
if(array_key_exists($hash, $this->stmts)) {
$stmt = $this->stmts[$hash];
$stmt->reset();
return $stmt;
}
return $this->stmts[$hash] = $this->dbConn->prepare($query);
}
public function remove(string $query): void {
unset($this->stmts[self::hash($query)]);
}
public function clear(): void {
foreach($this->stmts as $stmt)
$stmt->close();
$this->stmts = [];
}
}

View file

@ -3,8 +3,8 @@ namespace Misuzu\Emoticons;
use InvalidArgumentException;
use RuntimeException;
use Index\Data\DbStatementCache;
use Index\Data\IDbConnection;
use Misuzu\DbStatementCache;
class Emotes {
private const EMOTE_ORDER = [

View file

@ -4,9 +4,9 @@ namespace Misuzu\News;
use InvalidArgumentException;
use RuntimeException;
use Index\DateTime;
use Index\Data\DbStatementCache;
use Index\Data\IDbConnection;
use Index\Data\IDbResult;
use Misuzu\DbStatementCache;
use Misuzu\Pagination;
use Misuzu\Comments\CommentsCategoryInfo;
use Misuzu\Users\User;

View file

@ -3,10 +3,10 @@ namespace Misuzu\Profile;
use InvalidArgumentException;
use RuntimeException;
use Index\Data\DbStatementCache;
use Index\Data\DbTools;
use Index\Data\IDbConnection;
use Index\Data\IDbResult;
use Misuzu\DbStatementCache;
use Misuzu\Users\User;
class ProfileFields {