@codemem/server 0.26.0 → 0.26.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +28 -17
- package/dist/index.js.map +1 -1
- package/dist/routes/sync.d.ts.map +1 -1
- package/package.json +2 -2
- package/static/app.js +3 -3
package/dist/index.js
CHANGED
|
@@ -2272,30 +2272,40 @@ function syncRoutes(getStore, getSyncRuntimeStatus) {
|
|
|
2272
2272
|
app.get("/api/sync/status", async (c) => {
|
|
2273
2273
|
const store = getStore();
|
|
2274
2274
|
{
|
|
2275
|
+
const traceSync = (label, fn) => {
|
|
2276
|
+
if (process.env.CODEMEM_TRACE_SYNC_STATUS !== "1") return fn();
|
|
2277
|
+
const startedAt = Date.now();
|
|
2278
|
+
console.warn(`[codemem sync-status] ${label} start`);
|
|
2279
|
+
try {
|
|
2280
|
+
return fn();
|
|
2281
|
+
} finally {
|
|
2282
|
+
console.warn(`[codemem sync-status] ${label} ${Date.now() - startedAt}ms`);
|
|
2283
|
+
}
|
|
2284
|
+
};
|
|
2275
2285
|
const showDiag = queryBool(c.req.query("includeDiagnostics"));
|
|
2276
2286
|
const includeJoinRequests = queryBool(c.req.query("includeJoinRequests"));
|
|
2277
2287
|
const project = c.req.query("project") || null;
|
|
2278
|
-
const config = readCoordinatorSyncConfig();
|
|
2279
|
-
const syncReset = getSyncResetState(store.db);
|
|
2288
|
+
const config = traceSync("readCoordinatorSyncConfig", () => readCoordinatorSyncConfig());
|
|
2289
|
+
const syncReset = traceSync("getSyncResetState", () => getSyncResetState(store.db));
|
|
2280
2290
|
const d = drizzle(store.db, { schema });
|
|
2281
|
-
const deviceRow = d.select({
|
|
2291
|
+
const deviceRow = traceSync("deviceRow", () => d.select({
|
|
2282
2292
|
device_id: schema.syncDevice.device_id,
|
|
2283
2293
|
fingerprint: schema.syncDevice.fingerprint
|
|
2284
|
-
}).from(schema.syncDevice).limit(1).get();
|
|
2285
|
-
const daemonState = d.select().from(schema.syncDaemonState).where(eq(schema.syncDaemonState.id, 1)).get();
|
|
2286
|
-
const peerCountRow = d.select({ total: count() }).from(schema.syncPeers).get();
|
|
2294
|
+
}).from(schema.syncDevice).limit(1).get());
|
|
2295
|
+
const daemonState = traceSync("daemonState", () => d.select().from(schema.syncDaemonState).where(eq(schema.syncDaemonState.id, 1)).get());
|
|
2296
|
+
const peerCountRow = traceSync("peerCountRow", () => d.select({ total: count() }).from(schema.syncPeers).get());
|
|
2287
2297
|
let retentionState;
|
|
2288
2298
|
try {
|
|
2289
|
-
retentionState = d.select().from(schema.syncRetentionState).where(eq(schema.syncRetentionState.id, 1)).get();
|
|
2299
|
+
retentionState = traceSync("retentionState", () => d.select().from(schema.syncRetentionState).where(eq(schema.syncRetentionState.id, 1)).get());
|
|
2290
2300
|
} catch {
|
|
2291
2301
|
retentionState = void 0;
|
|
2292
2302
|
}
|
|
2293
|
-
const lastSyncRow = d.select({ last_sync_at: max(schema.syncPeers.last_sync_at) }).from(schema.syncPeers).get();
|
|
2294
|
-
const semanticIndex = redactSemanticIndexDiagnostics(getSemanticIndexDiagnostics(store.db), showDiag);
|
|
2303
|
+
const lastSyncRow = traceSync("lastSyncRow", () => d.select({ last_sync_at: max(schema.syncPeers.last_sync_at) }).from(schema.syncPeers).get());
|
|
2304
|
+
const semanticIndex = traceSync("semanticIndex", () => redactSemanticIndexDiagnostics(getSemanticIndexDiagnostics(store.db, { fastCounts: !showDiag }), showDiag));
|
|
2295
2305
|
const lastError = daemonState?.last_error;
|
|
2296
2306
|
const lastErrorAt = daemonState?.last_error_at;
|
|
2297
2307
|
const lastOkAt = daemonState?.last_ok_at;
|
|
2298
|
-
const viewerBinding = readViewerBinding(store.dbPath);
|
|
2308
|
+
const viewerBinding = traceSync("readViewerBinding", () => readViewerBinding(store.dbPath));
|
|
2299
2309
|
const daemonRunning = viewerBinding ? await portOpen(viewerBinding.host, viewerBinding.port) : false;
|
|
2300
2310
|
const daemonDetail = viewerBinding ? daemonRunning ? `viewer pidfile at ${viewerBinding.host}:${viewerBinding.port}` : `pidfile present but ${viewerBinding.host}:${viewerBinding.port} is unreachable` : null;
|
|
2301
2311
|
let daemonStateValue = "ok";
|
|
@@ -2346,14 +2356,14 @@ function syncRoutes(getStore, getSyncRuntimeStatus) {
|
|
|
2346
2356
|
statusPayload.daemon_running = runtimeStatus.phase === "starting" || daemonRunning;
|
|
2347
2357
|
statusPayload.daemon_detail = runtimeStatus.detail ?? daemonDetail;
|
|
2348
2358
|
}
|
|
2349
|
-
const peersItems = store.db.prepare(PEERS_QUERY).all().map((row) => {
|
|
2359
|
+
const peersItems = traceSync("peerRows", () => store.db.prepare(PEERS_QUERY).all()).map((row) => {
|
|
2350
2360
|
const peer = mapPeerRow(store, row, showDiag);
|
|
2351
2361
|
peer.status = peerStatus(peer);
|
|
2352
2362
|
return peer;
|
|
2353
2363
|
});
|
|
2354
2364
|
const peersMap = {};
|
|
2355
2365
|
for (const peer of peersItems) peersMap[String(peer.peer_device_id)] = peer.status;
|
|
2356
|
-
const attemptRows = d.select({
|
|
2366
|
+
const attemptRows = traceSync("attemptRows", () => d.select({
|
|
2357
2367
|
peer_device_id: schema.syncAttempts.peer_device_id,
|
|
2358
2368
|
ok: schema.syncAttempts.ok,
|
|
2359
2369
|
error: schema.syncAttempts.error,
|
|
@@ -2361,9 +2371,9 @@ function syncRoutes(getStore, getSyncRuntimeStatus) {
|
|
|
2361
2371
|
finished_at: schema.syncAttempts.finished_at,
|
|
2362
2372
|
ops_in: schema.syncAttempts.ops_in,
|
|
2363
2373
|
ops_out: schema.syncAttempts.ops_out
|
|
2364
|
-
}).from(schema.syncAttempts).orderBy(desc(schema.syncAttempts.finished_at)).limit(25).all();
|
|
2374
|
+
}).from(schema.syncAttempts).orderBy(desc(schema.syncAttempts.finished_at)).limit(25).all());
|
|
2365
2375
|
const peerAddressMap = /* @__PURE__ */ new Map();
|
|
2366
|
-
store.db.prepare("SELECT peer_device_id, addresses_json FROM sync_peers").all().forEach((peerRow) => {
|
|
2376
|
+
traceSync("peerAddressRows", () => store.db.prepare("SELECT peer_device_id, addresses_json FROM sync_peers").all()).forEach((peerRow) => {
|
|
2367
2377
|
const addrs = safeJsonList(peerRow.addresses_json);
|
|
2368
2378
|
if (addrs.length) peerAddressMap.set(String(peerRow.peer_device_id ?? ""), addrs);
|
|
2369
2379
|
});
|
|
@@ -2384,9 +2394,10 @@ function syncRoutes(getStore, getSyncRuntimeStatus) {
|
|
|
2384
2394
|
sync: {},
|
|
2385
2395
|
ping: {}
|
|
2386
2396
|
};
|
|
2387
|
-
const legacyDevices = store.claimableLegacyDeviceIds();
|
|
2388
|
-
const sharingReview = store.sharingReviewSummary(project);
|
|
2389
|
-
const
|
|
2397
|
+
const legacyDevices = traceSync("legacyDevices", () => store.claimableLegacyDeviceIds());
|
|
2398
|
+
const sharingReview = traceSync("sharingReview", () => store.sharingReviewSummary(project));
|
|
2399
|
+
const coordinatorSnapshot = await coordinatorStatusSnapshot(store, config);
|
|
2400
|
+
const coordinator = traceSync("coordinator", () => redactCoordinatorStatus(coordinatorSnapshot, showDiag));
|
|
2390
2401
|
let joinRequests = [];
|
|
2391
2402
|
if (includeJoinRequests && showDiag && config.syncCoordinatorAdminSecret) try {
|
|
2392
2403
|
joinRequests = await listCoordinatorJoinRequests(config);
|