fix: remove unnecessary calls to purgeCache (#3502)

This commit is contained in:
Dag 2023-07-06 18:52:19 +02:00 committed by GitHub
parent 965d7d44c5
commit 5e22459eb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 22 additions and 19 deletions

View File

@ -91,8 +91,9 @@ class DisplayAction implements ActionInterface
$cache = $cacheFactory->create();
$cache->setScope('');
$cache->purgeCache(86400);
$cache->setKey($cache_params);
// This cache purge will basically delete all cache items older than 24h, regardless of scope and key
$cache->purgeCache(86400);
$items = [];
$infos = [];
@ -215,7 +216,7 @@ class DisplayAction implements ActionInterface
$cache = $cacheFactory->create();
$cache->setScope('error_reporting');
$cache->setkey([$bridgeName . '_' . $code]);
$cache->purgeCache(86400);
if ($report = $cache->loadData()) {
$report = Json::decode($report);
$report['time'] = time();

View File

@ -48,7 +48,7 @@ class EZTVBridge extends BridgeAbstract
public function collectData()
{
$eztv_uri = $this->getEztvUri();
Debug::log($eztv_uri);
Logger::debug($eztv_uri);
$ids = explode(',', trim($this->getInput('ids')));
foreach ($ids as $id) {
$data = json_decode(getContents(sprintf('%s/api/get-torrents?imdb_id=%s', $eztv_uri, $id)));

View File

@ -223,10 +223,10 @@ EOD;
CURLOPT_POSTFIELDS => json_encode($request)
];
Debug::log("Sending GraphQL query:\n" . $query);
Debug::log("Sending GraphQL variables:\n" . json_encode($variables, JSON_PRETTY_PRINT));
Logger::debug("Sending GraphQL query:\n" . $query);
Logger::debug("Sending GraphQL variables:\n" . json_encode($variables, JSON_PRETTY_PRINT));
$response = json_decode(getContents('https://gql.twitch.tv/gql', $header, $opts));
Debug::log("Got GraphQL response:\n" . json_encode($response, JSON_PRETTY_PRINT));
Logger::debug("Got GraphQL response:\n" . json_encode($response, JSON_PRETTY_PRINT));
if (isset($response->errors)) {
$messages = array_column($response->errors, 'message');

View File

@ -228,6 +228,7 @@ EOD
$cache->setScope('twitter');
$cache->setKey(['cache']);
// todo: inspect mtime instead of purging with 3h
$cache->purgeCache(60 * 60 * 3);
$api = new TwitterClient($cache);

View File

@ -78,12 +78,19 @@ class FileCache implements CacheInterface
);
foreach ($cacheIterator as $cacheFile) {
if (in_array($cacheFile->getBasename(), ['.', '..', '.gitkeep'])) {
$basename = $cacheFile->getBasename();
$excluded = [
'.' => true,
'..' => true,
'.gitkeep' => true,
];
if (isset($excluded[$basename])) {
continue;
} elseif ($cacheFile->isFile()) {
if (filemtime($cacheFile->getPathname()) < time() - $seconds) {
$filepath = $cacheFile->getPathname();
if (filemtime($filepath) < time() - $seconds) {
// todo: sometimes this file doesn't exists
unlink($cacheFile->getPathname());
unlink($filepath);
}
}
}

View File

@ -52,7 +52,7 @@ final class RssBridge
$error = error_get_last();
if ($error) {
$message = sprintf(
'Fatal Error %s: %s in %s line %s',
'(shutdown) %s: %s in %s line %s',
$error['type'],
sanitize_root($error['message']),
sanitize_root($error['file']),

View File

@ -103,7 +103,6 @@ function getContents(
$cache = $cacheFactory->create();
$cache->setScope('server');
$cache->purgeCache(86400);
$cache->setKey([$url]);
// Snagged from https://github.com/lwthiker/curl-impersonate/blob/main/firefox/curl_ff102
@ -424,10 +423,7 @@ function getSimpleHTMLDOMCached(
$cache = $cacheFactory->create();
$cache->setScope('pages');
$cache->purgeCache(86400);
$params = [$url];
$cache->setKey($params);
$cache->setKey([$url]);
// Determine if cached file is within duration
$time = $cache->getTime();
@ -436,17 +432,15 @@ function getSimpleHTMLDOMCached(
&& time() - $duration < $time
&& !Debug::isEnabled()
) {
// Contents within duration and debug mode is disabled
// Cache hit
$content = $cache->loadData();
} else {
// Contents not within duration, or debug mode is enabled
$content = getContents(
$url,
$header ?? [],
$opts ?? []
);
// todo: fix bad if statement
if ($content !== false) {
if ($content) {
$cache->saveData($content);
}
}