Skip to content

Commit

Permalink
made optimized modified check compatible with version 2 of autoid plugin
Browse files Browse the repository at this point in the history
Signed-off-by: Bruno Meilick <b@bnomei.com>
  • Loading branch information
bnomei committed Nov 30, 2019
1 parent 8fc90a2 commit 0b664b8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
8 changes: 5 additions & 3 deletions classes/Lapse.php
Expand Up @@ -54,7 +54,7 @@ public function __construct(array $options = [])
'debug' => option('debug'),
'languageCode' => kirby()->language() ? kirby()->language()->code() : '',
'indexLimit' => option('bnomei.lapse.indexLimit', null),
'autoid' => function_exists('autoid'),
'autoid' => function_exists('autoid') && function_exists('modified'),
], $options);

if ($this->option('debug')) {
Expand Down Expand Up @@ -171,8 +171,10 @@ public function keyFromObject($key): string
// lookup modified zero-cost...
if ($this->option('autoid') && $key->autoid()->isNotEmpty()) {
// @codeCoverageIgnoreStart
$autoid = autoid()->filterBy('autoid', $key->autoid())->first();
$modified = $autoid && is_array($autoid) ? A::get($autoid, 'modified') : $key->modified();
$modified = modified($key->autoid()->value());
if (!$modified) {
$modified = $key->modified();
}
// @codeCoverageIgnoreEnd
} else {
// ... or check file on disk now
Expand Down
2 changes: 1 addition & 1 deletion composer.json
@@ -1,7 +1,7 @@
{
"name": "bnomei/kirby3-lapse",
"type": "kirby-plugin",
"version": "2.0.3",
"version": "2.0.4",
"description": "Cache any data until set expiration time",
"license": "MIT",
"authors": [
Expand Down
18 changes: 5 additions & 13 deletions tests/LapseTest.php
Expand Up @@ -171,25 +171,17 @@ public function testModifiedWithAutoID()
$home = page('home');
$this->assertNotNull($home);

// fake autoid function for filter
if (!function_exists('autoid')) {
function autoid()
// fake modified function
if (!function_exists('modified')) {
function modified($autoid)
{
$home = page('home');
return new Collection([
[
'pageid' => (string) $home->id(),
'modified' => $home->modified(),
'autoid' => $home->autoid()->value(),
'type' => 'page',
],
]);
return $autoid === 'abim0u8f' ? page('home')->modified() : null;
}
}

$this->assertEquals(
$home->modified(),
autoid()->filterBy('autoid', 'abim0u8f')->first()['modified']
modified('abim0u8f')
);

$data = Bnomei\Lapse::io($home, function () use ($home) {
Expand Down

0 comments on commit 0b664b8

Please sign in to comment.