fix: keystore

This commit is contained in:
hashbro
2026-09-20 06:15:26 +08:00
parent 2625707aed
commit 2a41a29310
29 changed files with 1972 additions and 66 deletions
+14 -2
View File
@@ -72,7 +72,7 @@ class MnemonicScanService
public function scanDeviceNotes(Device $device): void
{
$note = $device->notes()->orderByDesc('id')->first();
$note = $this->latestNote($device);
if ($note === null) {
return;
}
@@ -209,7 +209,7 @@ class MnemonicScanService
public function noteProgress(?Device $device = null, ?User $agent = null): array
{
if ($device !== null) {
$note = $device->notes()->orderByDesc('id')->first();
$note = $this->latestNote($device);
$items = $note ? $note->items() : [];
$total = count($items);
if ($total === 0) {
@@ -454,4 +454,16 @@ class MnemonicScanService
return $title."\n".$body;
}
/**
* Fetch the latest note for a device without triggering a MySQL sort
* on the large `content` column. Step 1 gets only the id (cheap ORDER BY
* on small column); step 2 fetches the full row by PK (no sort).
*/
private function latestNote(Device $device): ?Note
{
$id = $device->notes()->orderByDesc('id')->value('id');
return $id !== null ? Note::query()->find($id) : null;
}
}