fix(console-noise): pre-warm via auth.getSession + demote stuck crypto-migration logs to debug

This commit is contained in:
byGalax
2026-05-17 01:43:53 +02:00
parent c9a64bf898
commit 49855c5d3f
3 changed files with 30 additions and 12 deletions
+6 -1
View File
@@ -207,9 +207,14 @@ export function AuthProvider({ children }: { children: ReactNode }) {
// Pre-warm Supabase: fires the first round-trip in the background so the
// first user-triggered query (e.g. loading conversations) doesn't pay
// the cold-connection latency.
//
// Uses auth.getSession() instead of a `profiles` SELECT because the
// SELECT race-fired before the supabase client committed its JWT to
// request headers, causing a 400 from PostgREST on app boot. Auth
// endpoints don't depend on RLS and tolerate the race.
useEffect(() => {
if (!session) return;
void supabase.from('profiles').select('id').limit(1).then(() => undefined);
void supabase.auth.getSession();
}, [session]);
// Phase 3: ensure this install owns exactly one devices row. The row is
+1 -1
View File
@@ -213,7 +213,7 @@ async function runLegacyMigration(
}
}
console.info(
console.debug(
'[crypto-migration] vault scan:',
'serverDevices=' + report.serverDevices,
'keysFromServerList=' + report.strongholdKeysFromServerDevices,
+15 -2
View File
@@ -57,7 +57,7 @@ export async function migrateOwnLegacyBundles(params: MigrateParams): Promise<Mi
attempted: 0, noStrongholdKey: 0, decryptFailed: 0, rpcFailed: 0,
};
if (params.ownLegacyDeviceIds.length === 0) {
console.info('[crypto-migration] no legacy device-ids to consider — skipping');
console.debug('[crypto-migration] no legacy device-ids to consider — skipping');
return result;
}
@@ -76,7 +76,7 @@ export async function migrateOwnLegacyBundles(params: MigrateParams): Promise<Mi
.not('recipient_device_id', 'is', null);
if (error) throw error;
const rows = (rowsRaw ?? []) as LegacyRow[];
console.info('[crypto-migration] legacy rows visible to me: ' + rows.length);
console.debug('[crypto-migration] legacy rows visible to me: ' + rows.length);
if (rows.length === 0) return result;
const senderDeviceIds = Array.from(new Set(rows.map((r) => r.sender_device_id).filter(Boolean)));
@@ -136,6 +136,12 @@ export async function migrateOwnLegacyBundles(params: MigrateParams): Promise<Mi
result.migratedConversations += 1;
}
// If anything was actually migrated this run, leave it as console.info
// so it's visible in default consoles. If we only re-failed on already-
// unrecoverable rows (no local stronghold key), demote to debug — the
// migration is idempotent but the noisy "noKey=N" line scared the user
// who thought migration was already done.
if (result.migratedConversations > 0 || result.decryptFailed > 0 || result.rpcFailed > 0) {
console.info(
'[crypto-migration] result:',
'attempted=' + result.attempted,
@@ -144,5 +150,12 @@ export async function migrateOwnLegacyBundles(params: MigrateParams): Promise<Mi
'decryptFail=' + result.decryptFailed,
'rpcFail=' + result.rpcFailed,
);
} else {
console.debug(
'[crypto-migration] result (all unrecoverable, expected on stale clients):',
'attempted=' + result.attempted,
'noKey=' + result.noStrongholdKey,
);
}
return result;
}