Skip to content

Online Check

Note Reference Todo Sync

Note cards can reference site cards via sakura-site:// link syntax. When saving/deleting a note, the backend automatically syncs todo items to the referenced site cards.

Data Flow:

[text](sakura-site://siteId) reference in note content
        ↓ syncSiteTodosFromNotes()
Site card TodoItem.noteId field (linked to note ID)

Core Conventions (extensibility):

ConventionDescription
TodoItem.noteIdOptional field in types.ts. Has value = note-referenced auto-generated todo; no value = user manually added
siteInputSchema + memoUpdateSchemaBoth Zod schemas include noteId, ensuring the field is not lost during API saves
syncSiteTodosFromNotes()Called after every note CRUD operation, auto-adds/removes/retains todos
UI distinctionNote-referenced todos use indigo background, user-added todos use default color

Constraint: Note-referenced todos cannot be edited/deleted, only their completion status can be toggled.

Online Check

Online checking is managed centrally through the url_online_cache cache table. Multiple site cards with the same URL share check results, avoiding redundant checks within 20 hours.

Batch Check (scheduled/manual/post-import):

ComponentFileResponsibility
useOnlineCheckhooks/use-online-check.tsClient-side batch check trigger, refreshes page on completion
POST /api/site-cards/check-onlineapp/api/site-cards/check-online/route.tsSynchronous single-round batch check
OnlineCheckSchedulerlib/services/online-check-scheduler.tsDaily 4 AM scheduled check with retries
updateSitesOnlineStatuslib/services/site-repository.tsBatch update + offline notification trigger

Instant Check (new site/URL change):

ComponentFileResponsibility
useCardTagEditorhooks/use-site-tag-editor.tsFrontend trigger condition evaluation
performSingleSiteOnlineChecklib/services/online-check-service.tsSingle site online check service (cache query → HEAD→GET fallback → retry → update status → offline notification)
POST /api/site-cards/check-online-singleapp/api/site-cards/check-online-single/route.tsAPI route layer (auth + rate limit + service call)
updateSiteOnlineStatuslib/services/site-repository.tsDirectly set site online status

💡 Extensibility ConventionperformSingleSiteOnlineCheck(siteId) is the unified single-site online check service function. Frontend (via API route), API Token calls, and MCP tools all use this function with consistent trigger conditions (new site / URL change / siteSkipOnlineCheck toggle from off→on). Frontend's additional check-online-single call will hit the URL cache and won't re-check.

Trigger Scenarios:

ScenarioModeTrigger Condition
Admin manual triggerBatchuseOnlineCheck.handleRunOnlineCheck()
Post-import/resetBatchuseConfigActions.triggerPostImportOnlineCheck()
Daily 4 AMBatch (background)OnlineCheckScheduler scheduled trigger
New site creationInstantsiteSkipOnlineCheck=false, triggered by frontend/API/MCP
Site URL changeInstantMain URL differs from original snapshot, triggered by frontend/API/MCP
siteSkipOnlineCheck toggle off→onInstantAPI/MCP update detects switch change
MCP create/batch createInstantAsync performSingleSiteOnlineCheck after creation

UI States:

StateColorCondition
Onlinetext-emerald-400siteIsOnline=true
Offlinetext-red-400siteIsOnline=false
Not shownsiteSkipOnlineCheck=true or siteIsOnline=null (unchecked)

Cache Maintenance (provided by url-online-cache-repository.ts):

FunctionResponsibility
getUrlOnlineStatusIfFresh(url)Query single URL cache (valid for 20 hours)
getUrlsOnlineStatusBatch(urls)Batch query URL cache
upsertUrlOnlineCache(url, siteIsOnline)Single URL cache write
upsertUrlOnlineCacheBatch(results)Batch URL cache write
cleanOrphanUrlCache()Clean URL cache entries no longer used by any site
applyUrlCacheToSites()Apply cache to all sites

💡 Extensibility Convention — The url_online_cache table is registered in sql-dialect.ts's UPSERT_CONFLICT_COLUMNS, ensuring INSERT OR REPLACE is correctly translated to UPSERT on MySQL/PostgreSQL.