From 8ca1b2b90adab9b8cde12a762003f1fc6a9e756a Mon Sep 17 00:00:00 2001 From: Anish Sarkar <104695310+AnishSarkar22@users.noreply.github.com> Date: Fri, 30 Jan 2026 17:20:11 +0530 Subject: [PATCH] refactor(ElectricClient): update debug mode for electricSync to activate only in development environment --- surfsense_web/lib/electric/client.ts | 45 ++++++++++++++-------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/surfsense_web/lib/electric/client.ts b/surfsense_web/lib/electric/client.ts index 148da58ec..d25e268be 100644 --- a/surfsense_web/lib/electric/client.ts +++ b/surfsense_web/lib/electric/client.ts @@ -165,8 +165,8 @@ export async function initElectric(userId: string): Promise { dataDir: dbName, relaxedDurability: true, extensions: { - // Enable debug mode in electricSync to see detailed sync logs - electric: electricSync({ debug: true }), + // Enable debug mode in electricSync only in development + electric: electricSync({ debug: process.env.NODE_ENV === "development" }), live, // Enable live queries for real-time updates }, }); @@ -341,26 +341,27 @@ export async function initElectric(userId: string): Promise { console.log("[Electric] Where clause:", where, "Validated:", validatedWhere); try { - // Debug: Test Electric SQL connection directly first - // Use validatedWhere to ensure proper URL encoding - const testUrl = `${electricUrl}/v1/shape?table=${table}&offset=-1${validatedWhere ? `&where=${encodeURIComponent(validatedWhere)}` : ""}`; - console.log("[Electric] Testing Electric SQL directly:", testUrl); - try { - const testResponse = await fetch(testUrl); - const testHeaders = { - handle: testResponse.headers.get("electric-handle"), - offset: testResponse.headers.get("electric-offset"), - upToDate: testResponse.headers.get("electric-up-to-date"), - }; - console.log("[Electric] Direct Electric SQL response headers:", testHeaders); - const testData = await testResponse.json(); - console.log( - "[Electric] Direct Electric SQL data count:", - Array.isArray(testData) ? testData.length : "not array", - testData - ); - } catch (testErr) { - console.error("[Electric] Direct Electric SQL test failed:", testErr); + // Debug: Test Electric SQL connection directly first (DEV ONLY - skipped in production) + if (process.env.NODE_ENV === "development") { + const testUrl = `${electricUrl}/v1/shape?table=${table}&offset=-1${validatedWhere ? `&where=${encodeURIComponent(validatedWhere)}` : ""}`; + console.log("[Electric] Testing Electric SQL directly:", testUrl); + try { + const testResponse = await fetch(testUrl); + const testHeaders = { + handle: testResponse.headers.get("electric-handle"), + offset: testResponse.headers.get("electric-offset"), + upToDate: testResponse.headers.get("electric-up-to-date"), + }; + console.log("[Electric] Direct Electric SQL response headers:", testHeaders); + const testData = await testResponse.json(); + console.log( + "[Electric] Direct Electric SQL data count:", + Array.isArray(testData) ? testData.length : "not array", + testData + ); + } catch (testErr) { + console.error("[Electric] Direct Electric SQL test failed:", testErr); + } } // Use PGlite's electric sync plugin to sync the shape