From 0b664b8d91c9fa820bf8a2164825944dbb02c584 Mon Sep 17 00:00:00 2001 From: Bruno Meilick Date: Sat, 30 Nov 2019 17:25:23 +0000 Subject: [PATCH] made optimized modified check compatible with version 2 of autoid plugin Signed-off-by: Bruno Meilick --- classes/Lapse.php | 8 +++++--- composer.json | 2 +- tests/LapseTest.php | 18 +++++------------- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/classes/Lapse.php b/classes/Lapse.php index be4bebd..a2336ad 100644 --- a/classes/Lapse.php +++ b/classes/Lapse.php @@ -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')) { @@ -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 diff --git a/composer.json b/composer.json index 006ae91..b28208f 100644 --- a/composer.json +++ b/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": [ diff --git a/tests/LapseTest.php b/tests/LapseTest.php index 8e392ef..937b916 100644 --- a/tests/LapseTest.php +++ b/tests/LapseTest.php @@ -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) {