Skip to content

Commit

Permalink
Simplepie846 (#23)
Browse files Browse the repository at this point in the history
* Merge SimplePie fix 846
simplepie#846

* Fix tests running in the same second
  • Loading branch information
Alkarex authored Sep 14, 2024
1 parent cc0e6e1 commit 8458f8d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/SimplePie.php
Original file line number Diff line number Diff line change
Expand Up @@ -1949,7 +1949,7 @@ protected function fetch_data(&$cache)
$this->data = [];
}
// Check if the cache has been updated
elseif (empty($this->data['cache_expiration_time']) || $this->data['cache_expiration_time'] > time()) { // FreshRSS
elseif (empty($this->data['cache_expiration_time']) || $this->data['cache_expiration_time'] < time()) { // FreshRSS https://github.com/simplepie/simplepie/pull/846
// Want to know if we tried to send last-modified and/or etag headers
// when requesting this file. (Note that it's up to the file to
// support this, but we don't always send the headers either.)
Expand All @@ -1973,6 +1973,7 @@ protected function fetch_data(&$cache)
$this->status_code = 0;

if ($this->force_cache_fallback) {
$this->data['cache_expiration_time'] = $this->cache_duration + time(); // FreshRSS
$cache->set_data($cacheKey, $this->data, $this->cache_duration);

return true;
Expand All @@ -1987,6 +1988,7 @@ protected function fetch_data(&$cache)
$this->raw_data = false;
if (isset($file)) { // FreshRSS
// Update cache metadata
$this->data['cache_expiration_time'] = $this->cache_duration + time();
$this->data['headers'] = array_map(function (array $values): string {
return implode(',', $values);
}, $file->get_headers());
Expand All @@ -2000,6 +2002,7 @@ protected function fetch_data(&$cache)
$hash = $this->clean_hash($file->get_body_content());
if (($this->data['hash'] ?? null) === $hash) {
// Update cache metadata
$this->data['cache_expiration_time'] = $this->cache_duration + time();
$this->data['headers'] = array_map(function (array $values): string {
return implode(',', $values);
}, $file->get_headers());
Expand Down
6 changes: 3 additions & 3 deletions tests/Integration/CachingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function testInitWithDifferentCacheStateCallsCacheCorrectly(
*/
public static function provideSavedCacheData(): array
{
$defaultMtime = time();
$defaultMtime = time() - 1; // FreshRSS: -1 to account for tests running in the same second
$defaultExpirationTime = $defaultMtime + 3600;

$expectDefaultDataWritten = [
Expand Down Expand Up @@ -256,10 +256,10 @@ public static function provideSavedCacheData(): array
[CacheInterface::class, $currentlyCachedDataWithNonFeedUrl, $expectDataWithNewFeedUrl, $defaultMtime],
// Check if the cache has been updated
[Base::class, $currentlyCachedDataIsUpdated, $expectDefaultDataWritten, $defaultMtime],
[CacheInterface::class, $currentlyCachedDataIsUpdated, $expectDefaultDataWritten, $defaultMtime],
[CacheInterface::class, $currentlyCachedDataIsUpdated, $expectNoDataWritten, $defaultMtime], // FreshRSS https://github.com/simplepie/simplepie/pull/846
// If the cache is still valid, just return true
[Base::class, $currentlyCachedDataIsValid, $expectDefaultDataWritten, $defaultMtime],
[CacheInterface::class, $currentlyCachedDataIsValid, $expectNoDataWritten, $defaultMtime],
[CacheInterface::class, $currentlyCachedDataIsValid, $expectDefaultDataWritten, $defaultMtime], // FreshRSS https://github.com/simplepie/simplepie/pull/846
];
}
}

0 comments on commit 8458f8d

Please sign in to comment.