ReportQueries.php: remove caching, since posts can be removed from the outside

This commit is contained in:
Zankaria 2024-12-08 13:29:33 +01:00
parent 88564ca12e
commit d3782562b8

View file

@ -5,10 +5,7 @@ use Vichan\Data\Driver\CacheDriver;
class ReportQueries {
private const CACHE_KEY = "report_queries_valid_count";
private \PDO $pdo;
private CacheDriver $cache;
private bool $auto_maintenance;
@ -119,9 +116,8 @@ class ReportQueries {
* @param CacheDriver $cache Cache driver.
* @param bool $auto_maintenance If the auto maintenance should be enabled.
*/
public function __construct(\PDO $pdo, CacheDriver $cache, bool $auto_maintenance) {
public function __construct(\PDO $pdo, bool $auto_maintenance) {
$this->pdo = $pdo;
$this->cache = $cache;
$this->auto_maintenance = $auto_maintenance;
}
@ -131,18 +127,13 @@ class ReportQueries {
* @return int The number of reports.
*/
public function getCount(): int {
$ret = $this->cache->get(self::CACHE_KEY);
if ($ret === null) {
$query = $this->pdo->prepare("SELECT `board`, `post`, `id` FROM `reports`");
$query->execute();
$raw_reports = $query->fetchAll(\PDO::FETCH_ASSOC);
$valid_reports = $this->filterReports($raw_reports, false, null);
$count = \count($valid_reports);
$query = $this->pdo->prepare("SELECT `board`, `post`, `id` FROM `reports`");
$query->execute();
$raw_reports = $query->fetchAll(\PDO::FETCH_ASSOC);
$valid_reports = $this->filterReports($raw_reports, false, null);
$count = \count($valid_reports);
$this->cache->set(self::CACHE_KEY, $count);
return $count;
}
return $ret;
return $count;
}
/**
@ -203,8 +194,6 @@ class ReportQueries {
$query = $this->pdo->prepare("DELETE FROM `reports` WHERE `id` = :id");
$query->bindValue(':id', $id, \PDO::PARAM_INT);
$query->execute();
// The caller may actually delete a valid post, so we need to invalidate the cache.
$this->cache->delete(self::CACHE_KEY);
}
/**
@ -216,8 +205,6 @@ class ReportQueries {
$query = $this->pdo->prepare("DELETE FROM `reports` WHERE `ip` = :ip");
$query->bindValue(':ip', $ip);
$query->execute();
// The caller may actually delete a valid post, so we need to invalidate the cache.
$this->cache->delete(self::CACHE_KEY);
}
/**
@ -237,7 +224,5 @@ class ReportQueries {
$query->bindValue(':post', $post_id, \PDO::PARAM_INT);
$query->bindValue(':reason', $reason);
$query->execute();
$this->cache->delete(self::CACHE_KEY);
}
}