forked from leftypol/leftypol
ReportQueries.php: remove caching, since posts can be removed from the outside
This commit is contained in:
parent
88564ca12e
commit
d3782562b8
1 changed files with 7 additions and 22 deletions
|
@ -5,10 +5,7 @@ use Vichan\Data\Driver\CacheDriver;
|
||||||
|
|
||||||
|
|
||||||
class ReportQueries {
|
class ReportQueries {
|
||||||
private const CACHE_KEY = "report_queries_valid_count";
|
|
||||||
|
|
||||||
private \PDO $pdo;
|
private \PDO $pdo;
|
||||||
private CacheDriver $cache;
|
|
||||||
private bool $auto_maintenance;
|
private bool $auto_maintenance;
|
||||||
|
|
||||||
|
|
||||||
|
@ -119,9 +116,8 @@ class ReportQueries {
|
||||||
* @param CacheDriver $cache Cache driver.
|
* @param CacheDriver $cache Cache driver.
|
||||||
* @param bool $auto_maintenance If the auto maintenance should be enabled.
|
* @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->pdo = $pdo;
|
||||||
$this->cache = $cache;
|
|
||||||
$this->auto_maintenance = $auto_maintenance;
|
$this->auto_maintenance = $auto_maintenance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,18 +127,13 @@ class ReportQueries {
|
||||||
* @return int The number of reports.
|
* @return int The number of reports.
|
||||||
*/
|
*/
|
||||||
public function getCount(): int {
|
public function getCount(): int {
|
||||||
$ret = $this->cache->get(self::CACHE_KEY);
|
$query = $this->pdo->prepare("SELECT `board`, `post`, `id` FROM `reports`");
|
||||||
if ($ret === null) {
|
$query->execute();
|
||||||
$query = $this->pdo->prepare("SELECT `board`, `post`, `id` FROM `reports`");
|
$raw_reports = $query->fetchAll(\PDO::FETCH_ASSOC);
|
||||||
$query->execute();
|
$valid_reports = $this->filterReports($raw_reports, false, null);
|
||||||
$raw_reports = $query->fetchAll(\PDO::FETCH_ASSOC);
|
$count = \count($valid_reports);
|
||||||
$valid_reports = $this->filterReports($raw_reports, false, null);
|
|
||||||
$count = \count($valid_reports);
|
|
||||||
|
|
||||||
$this->cache->set(self::CACHE_KEY, $count);
|
return $count;
|
||||||
return $count;
|
|
||||||
}
|
|
||||||
return $ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -203,8 +194,6 @@ class ReportQueries {
|
||||||
$query = $this->pdo->prepare("DELETE FROM `reports` WHERE `id` = :id");
|
$query = $this->pdo->prepare("DELETE FROM `reports` WHERE `id` = :id");
|
||||||
$query->bindValue(':id', $id, \PDO::PARAM_INT);
|
$query->bindValue(':id', $id, \PDO::PARAM_INT);
|
||||||
$query->execute();
|
$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 = $this->pdo->prepare("DELETE FROM `reports` WHERE `ip` = :ip");
|
||||||
$query->bindValue(':ip', $ip);
|
$query->bindValue(':ip', $ip);
|
||||||
$query->execute();
|
$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(':post', $post_id, \PDO::PARAM_INT);
|
||||||
$query->bindValue(':reason', $reason);
|
$query->bindValue(':reason', $reason);
|
||||||
$query->execute();
|
$query->execute();
|
||||||
|
|
||||||
$this->cache->delete(self::CACHE_KEY);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue