mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-31 19:45:15 +02:00
refactor(ElectricClient): update debug mode for electricSync to activate only in development environment
This commit is contained in:
parent
6aa3d88f68
commit
8ca1b2b90a
1 changed files with 23 additions and 22 deletions
|
|
@ -165,8 +165,8 @@ export async function initElectric(userId: string): Promise<ElectricClient> {
|
||||||
dataDir: dbName,
|
dataDir: dbName,
|
||||||
relaxedDurability: true,
|
relaxedDurability: true,
|
||||||
extensions: {
|
extensions: {
|
||||||
// Enable debug mode in electricSync to see detailed sync logs
|
// Enable debug mode in electricSync only in development
|
||||||
electric: electricSync({ debug: true }),
|
electric: electricSync({ debug: process.env.NODE_ENV === "development" }),
|
||||||
live, // Enable live queries for real-time updates
|
live, // Enable live queries for real-time updates
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
@ -341,26 +341,27 @@ export async function initElectric(userId: string): Promise<ElectricClient> {
|
||||||
console.log("[Electric] Where clause:", where, "Validated:", validatedWhere);
|
console.log("[Electric] Where clause:", where, "Validated:", validatedWhere);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Debug: Test Electric SQL connection directly first
|
// Debug: Test Electric SQL connection directly first (DEV ONLY - skipped in production)
|
||||||
// Use validatedWhere to ensure proper URL encoding
|
if (process.env.NODE_ENV === "development") {
|
||||||
const testUrl = `${electricUrl}/v1/shape?table=${table}&offset=-1${validatedWhere ? `&where=${encodeURIComponent(validatedWhere)}` : ""}`;
|
const testUrl = `${electricUrl}/v1/shape?table=${table}&offset=-1${validatedWhere ? `&where=${encodeURIComponent(validatedWhere)}` : ""}`;
|
||||||
console.log("[Electric] Testing Electric SQL directly:", testUrl);
|
console.log("[Electric] Testing Electric SQL directly:", testUrl);
|
||||||
try {
|
try {
|
||||||
const testResponse = await fetch(testUrl);
|
const testResponse = await fetch(testUrl);
|
||||||
const testHeaders = {
|
const testHeaders = {
|
||||||
handle: testResponse.headers.get("electric-handle"),
|
handle: testResponse.headers.get("electric-handle"),
|
||||||
offset: testResponse.headers.get("electric-offset"),
|
offset: testResponse.headers.get("electric-offset"),
|
||||||
upToDate: testResponse.headers.get("electric-up-to-date"),
|
upToDate: testResponse.headers.get("electric-up-to-date"),
|
||||||
};
|
};
|
||||||
console.log("[Electric] Direct Electric SQL response headers:", testHeaders);
|
console.log("[Electric] Direct Electric SQL response headers:", testHeaders);
|
||||||
const testData = await testResponse.json();
|
const testData = await testResponse.json();
|
||||||
console.log(
|
console.log(
|
||||||
"[Electric] Direct Electric SQL data count:",
|
"[Electric] Direct Electric SQL data count:",
|
||||||
Array.isArray(testData) ? testData.length : "not array",
|
Array.isArray(testData) ? testData.length : "not array",
|
||||||
testData
|
testData
|
||||||
);
|
);
|
||||||
} catch (testErr) {
|
} catch (testErr) {
|
||||||
console.error("[Electric] Direct Electric SQL test failed:", testErr);
|
console.error("[Electric] Direct Electric SQL test failed:", testErr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use PGlite's electric sync plugin to sync the shape
|
// Use PGlite's electric sync plugin to sync the shape
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue