v2.0.10 — snappier boot + non-blocking relay push on save
DB - Six indices on the cards table (position+created_at, bucket_id, parent_id, updated_at, caldav_uid, relay_uid). The /api/cards ORDER BY position was a full-table scan + sort on every board reload; now it's an index walk. - PRAGMA synchronous=NORMAL (safe under WAL) + temp_store=MEMORY. Save path - pushCardToRelayRead and deleteCardFromRelayRead now run AFTER the response is flushed via fastcgi_finish_request (falls back to ignore_user_abort + flush on non-FPM setups). The user's save no longer blocks on the relay round-trip. - cURL timeouts dropped from 10s/30s to 5s/10s, plus a 2s connect-timeout. Worst-case on a dead relay goes from ~160s down to ~15s — and now that worst case is in the background anyway. Client - loadCards phase-2 batches bumped from 25 to 500 cards per fetch. For 300 cards that's 1 HTTP trip instead of 12 — spinner wall time drops from ~3s to ~0.25s. - renderBoard() is now requestAnimationFrame-coalesced. The boot sequence calls renderBoard from cache paint, meta paint, body paint, and the cards.reloaded plugin hook; they used to each trigger an innerHTML swap + layout pass. Now they collapse into one actual render per frame. Callers that really need a sync render (rare) can use the new renderBoardSync(). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
87ebcd156b
commit
2d58cd993e
7 files changed
+124
-28
No files matched your search
+54
-21
@@ -312,13 +312,19 @@ if (str_starts_with($route, '/api/')) {
|
||||
'body' => hyprcrdRelayEncrypt($body, $relayKey),
|
||||
'hero_filename' => $heroFilename,
|
||||
]);
|
||||
// Aggressive timeouts: read-later is opt-in + best-effort. If the
|
||||
// relay is slow or unreachable we must NOT block the user's save —
|
||||
// this function still runs inline from the PATCH handler (we'll
|
||||
// also flush the response before invoking it), so the shorter
|
||||
// timeout caps the worst-case backlog even if flushing fails.
|
||||
$ch = curl_init(rtrim($relayUrl, '/') . '/api/read');
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_POST => true,
|
||||
CURLOPT_POSTFIELDS => $payload,
|
||||
CURLOPT_HTTPHEADER => ['Content-Type: application/json', 'X-Relay-User: ' . $relayUser, 'X-Relay-Key: ' . $relayKey],
|
||||
CURLOPT_TIMEOUT => 10,
|
||||
CURLOPT_CONNECTTIMEOUT => 2,
|
||||
CURLOPT_TIMEOUT => 5,
|
||||
]);
|
||||
hyprcrdApplySafeCurlOpts($ch);
|
||||
$resp = curl_exec($ch);
|
||||
@@ -348,7 +354,8 @@ if (str_starts_with($route, '/api/')) {
|
||||
CURLOPT_POST => true,
|
||||
CURLOPT_POSTFIELDS => $attPayload,
|
||||
CURLOPT_HTTPHEADER => ['Content-Type: application/json', 'X-Relay-User: ' . $relayUser, 'X-Relay-Key: ' . $relayKey],
|
||||
CURLOPT_TIMEOUT => 30,
|
||||
CURLOPT_CONNECTTIMEOUT => 2,
|
||||
CURLOPT_TIMEOUT => 10,
|
||||
]);
|
||||
hyprcrdApplySafeCurlOpts($ach);
|
||||
curl_exec($ach);
|
||||
@@ -367,7 +374,8 @@ if (str_starts_with($route, '/api/')) {
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_CUSTOMREQUEST => 'DELETE',
|
||||
CURLOPT_HTTPHEADER => ['X-Relay-User: ' . $relayUser, 'X-Relay-Key: ' . $relayKey],
|
||||
CURLOPT_TIMEOUT => 10,
|
||||
CURLOPT_CONNECTTIMEOUT => 2,
|
||||
CURLOPT_TIMEOUT => 5,
|
||||
]);
|
||||
hyprcrdApplySafeCurlOpts($ch);
|
||||
curl_exec($ch);
|
||||
@@ -397,13 +405,21 @@ if (str_starts_with($route, '/api/')) {
|
||||
'read_push' => $readPush,
|
||||
]);
|
||||
$saved = $db->query('SELECT c.*, b.name as bucket_name FROM cards c LEFT JOIN buckets b ON c.bucket_id = b.id WHERE c.id = ' . $db->lastInsertId())->fetch();
|
||||
if ($readPush && $saved) {
|
||||
pushCardToRelayRead($saved, $db);
|
||||
// relay_uid may have been generated inside the push helper;
|
||||
// re-read so the client sees it on the response.
|
||||
$saved = $db->query('SELECT c.*, b.name as bucket_name FROM cards c LEFT JOIN buckets b ON c.bucket_id = b.id WHERE c.id = ' . (int)$saved['id'])->fetch();
|
||||
// When the card opts into read-later, generate the relay_uid up
|
||||
// front so the response the client receives already carries it.
|
||||
// Actually pushing to the relay happens AFTER the response is
|
||||
// flushed — the relay hop is best-effort and shouldn't stretch
|
||||
// the user-facing save latency.
|
||||
if ($readPush && $saved && empty($saved['relay_uid'])) {
|
||||
$uid = bin2hex(random_bytes(16));
|
||||
$db->prepare('UPDATE cards SET relay_uid = ? WHERE id = ?')->execute([$uid, $saved['id']]);
|
||||
$saved['relay_uid'] = $uid;
|
||||
}
|
||||
echo json_encode($saved);
|
||||
if ($readPush && $saved) {
|
||||
hyprcrdFinishRequest();
|
||||
pushCardToRelayRead($saved, $db);
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -436,11 +452,15 @@ if (str_starts_with($route, '/api/')) {
|
||||
if ($cardRow && !empty($cardRow['caldav_uid'])) {
|
||||
$db->prepare('INSERT OR REPLACE INTO caldav_tombstones (caldav_uid, card_id) VALUES (?, ?)')->execute([$cardRow['caldav_uid'], $m[1]]);
|
||||
}
|
||||
if ($cardRow && (int)($cardRow['read_push'] ?? 0) === 1 && !empty($cardRow['relay_uid'])) {
|
||||
deleteCardFromRelayRead((string)$cardRow['relay_uid'], $db);
|
||||
}
|
||||
$wipeFromRelay = ($cardRow && (int)($cardRow['read_push'] ?? 0) === 1 && !empty($cardRow['relay_uid']))
|
||||
? (string)$cardRow['relay_uid'] : null;
|
||||
$db->prepare('DELETE FROM cards WHERE id = :id')->execute(['id' => $m[1]]);
|
||||
echo json_encode(['ok' => true]); exit;
|
||||
echo json_encode(['ok' => true]);
|
||||
if ($wipeFromRelay) {
|
||||
hyprcrdFinishRequest();
|
||||
deleteCardFromRelayRead($wipeFromRelay, $db);
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
if (preg_match('#^/api/cards/(\d+)/history$#', $route, $m) && $method === 'GET') {
|
||||
@@ -491,21 +511,34 @@ if (str_starts_with($route, '/api/')) {
|
||||
if ($fields) { $fields[] = 'updated_at = datetime("now")'; $db->prepare('UPDATE cards SET ' . implode(', ', $fields) . ' WHERE id = :id')->execute($params); }
|
||||
$card = $db->prepare('SELECT c.*, b.name as bucket_name FROM cards c LEFT JOIN buckets b ON c.bucket_id = b.id WHERE c.id = :id');
|
||||
$card->execute(['id' => $m[1]]); $savedCard = $card->fetch();
|
||||
// Relay sync:
|
||||
// - if card currently wants to be in the read list, push (idempotent
|
||||
// upsert keeps the remote copy in sync on every edit).
|
||||
// - if the user just toggled it off, clean up remotely.
|
||||
// Decide the relay-sync action BEFORE echoing the response, then
|
||||
// flush + run the actual cURL hop afterwards. The user doesn't
|
||||
// wait for the relay round-trip; a dead/slow relay no longer
|
||||
// stretches the card save into "eine Ewigkeit".
|
||||
$pushAction = null; // 'push' | 'delete' | null
|
||||
if ($savedCard) {
|
||||
$nowRead = (int)($savedCard['read_push'] ?? 0);
|
||||
if ($nowRead === 1) {
|
||||
pushCardToRelayRead($savedCard, $db);
|
||||
// Re-read to surface any newly-generated relay_uid on the wire.
|
||||
$card->execute(['id' => $m[1]]); $savedCard = $card->fetch();
|
||||
// Mint relay_uid up front so the response carries it.
|
||||
if (empty($savedCard['relay_uid'])) {
|
||||
$uid = bin2hex(random_bytes(16));
|
||||
$db->prepare('UPDATE cards SET relay_uid = ? WHERE id = ?')->execute([$uid, $savedCard['id']]);
|
||||
$savedCard['relay_uid'] = $uid;
|
||||
}
|
||||
$pushAction = 'push';
|
||||
} elseif ($prevRead === 1 && $prevRelayUid) {
|
||||
deleteCardFromRelayRead($prevRelayUid, $db);
|
||||
$pushAction = 'delete';
|
||||
}
|
||||
}
|
||||
echo json_encode($savedCard); exit;
|
||||
echo json_encode($savedCard);
|
||||
if ($pushAction === 'push') {
|
||||
hyprcrdFinishRequest();
|
||||
pushCardToRelayRead($savedCard, $db);
|
||||
} elseif ($pushAction === 'delete') {
|
||||
hyprcrdFinishRequest();
|
||||
deleteCardFromRelayRead((string)$prevRelayUid, $db);
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
// Plugins
|
||||
|
||||
Reference in new issue
Block a user