Skip to content
This repository was archived by the owner on May 18, 2025. It is now read-only.

Commit ebc46b9

Browse files
committed
🐛 modified() did not match autoid version
1 parent e09cfbd commit ebc46b9

File tree

8 files changed

+287
-65
lines changed

8 files changed

+287
-65
lines changed

classes/BoostIndex.php

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function write(): bool
5656
return false;
5757
}
5858

59-
public function index(bool $force = false): int
59+
public function index(bool $force = false, ?Page $target = null): int
6060
{
6161
$count = $this->index ? count($this->index) : 0;
6262
if ($count > 0 && !$force) {
@@ -70,6 +70,15 @@ public function index(bool $force = false): int
7070
if ($this->add($page)) {
7171
$count++;
7272
}
73+
// save every n steps
74+
if ($count % 2000 === 0) {
75+
$this->write();
76+
}
77+
// only search until target is found
78+
if ($target && $target->id() === $page->id()) {
79+
$this->write();
80+
break;
81+
}
7382
}
7483
return $count;
7584
}
@@ -94,12 +103,16 @@ public function findByBoostId(string $boostid, bool $throwException = true): ?Pa
94103
if ($id && $page = bolt(explode(static::SEPERATOR, $id)[0])) {
95104
return $page;
96105
} else {
97-
$crawl = kirby()->collection('boostidpages')->filter(function ($page) use ($boostid) {
98-
return $page->boostIDField()->value() === $boostid;
99-
});
100-
if ($page = $crawl->first()) {
101-
$page->boostIndexAdd();
102-
return $page;
106+
$crawl = null;
107+
foreach (kirby()->collection('boostidpages') as $page) {
108+
if ($this->add($page) && $page->boostIDField()->value() === $boostid) {
109+
$crawl = $page;
110+
break;
111+
}
112+
}
113+
$this->write();
114+
if ($crawl) {
115+
return $crawl;
103116
} elseif ($throwException) {
104117
$this->write();
105118
throw new \Exception("No page found for BoostID: " . $boostid);
@@ -175,8 +188,11 @@ public static function tinyurl($id): string
175188
return rtrim($url, '/') . '/' . $id;
176189
}
177190

178-
public static function modified(string $id): ?int
191+
public static function modified($id): ?int
179192
{
193+
if (is_a($id, \Kirby\Cms\Page::class)) {
194+
$id = $id->id();
195+
}
180196
$modified = BoostCache::singleton()->get(crc32($id) . '-modified');
181197
if ($modified) {
182198
return $modified;

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "bnomei/kirby3-boost",
33
"type": "kirby-plugin",
4-
"version": "1.6.0",
4+
"version": "1.6.1",
55
"description": "Boost the speed of Kirby by having content files of pages cached, with automatic unique ID, fast lookup and Tiny-URL.",
66
"license": "MIT",
77
"authors": [

composer.lock

Lines changed: 120 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function bolt(string $id)
1212
}
1313

1414
if (! function_exists('modified')) {
15-
function modified(string $id)
15+
function modified($id)
1616
{
1717
return \Bnomei\BoostIndex::modified($id);
1818
}

0 commit comments

Comments
 (0)