Skip to content

Commit 3d0001a

Browse files
rdhyeeclaude
andauthored
fix: Remove mutable OJS syntax causing runtime errors (#42)
The `mutable dbState` declaration was causing "mutable dbState is not defined" errors in the browser. This was due to OJS/Quarto syntax issues with the mutable keyword. Simplified the approach: - Removed mutable state tracking entirely - initDatabases now returns { narrow, wide } on success or { error } on failure - dbNarrow/dbWide derived from initDatabases with proper null checks This follows the simpler pattern used in parquet_cesium.qmd. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <[email protected]>
1 parent a755aee commit 3d0001a

File tree

1 file changed

+5
-25
lines changed

1 file changed

+5
-25
lines changed

tutorials/narrow_vs_wide_performance.qmd

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -104,61 +104,41 @@ viewof runBenchmarks = Inputs.button("Run All Benchmarks", {
104104
<div id="error_display" style="padding: 10px; background: #f8d7da; border-radius: 4px; color: #721c24; display: none;">
105105
</div>
106106

107-
```{ojs}
108-
//| echo: false
109-
// Database initialization is lazy - only happens when button is clicked
110-
// This is stored as a mutable to track state
111-
mutable dbState = { narrow: null, wide: null, error: null, initialized: false }
112-
```
113-
114107
```{ojs}
115108
//| echo: false
116109
// Initialize databases only when button is clicked (lazy loading)
110+
// Returns { narrow, wide } or null if not yet clicked
117111
initDatabases = {
118-
// Only initialize when button is clicked
119112
if (runBenchmarks < 1) return null;
120113
121-
// Return cached instances if already initialized
122-
if (dbState.initialized && !dbState.error) {
123-
return { narrow: dbState.narrow, wide: dbState.wide };
124-
}
125-
126114
const loadingDiv = document.getElementById('loading_init');
127115
const errorDiv = document.getElementById('error_display');
128116
129117
if (loadingDiv) loadingDiv.style.display = 'block';
130118
if (errorDiv) errorDiv.style.display = 'none';
131119
132120
try {
133-
// Initialize narrow database
134121
const narrowDb = await DuckDBClient.of();
135122
await narrowDb.query(`CREATE VIEW narrow AS SELECT * FROM read_parquet('${narrowUrl}')`);
136123
137-
// Initialize wide database
138124
const wideDb = await DuckDBClient.of();
139125
await wideDb.query(`CREATE VIEW wide AS SELECT * FROM read_parquet('${wideUrl}')`);
140126
141-
// Cache the instances
142-
mutable dbState = { narrow: narrowDb, wide: wideDb, error: null, initialized: true };
143-
127+
if (loadingDiv) loadingDiv.style.display = 'none';
144128
return { narrow: narrowDb, wide: wideDb };
145129
} catch (e) {
146130
const errorMsg = `Failed to initialize databases: ${e.message}. This may be due to network issues or CORS restrictions.`;
147-
mutable dbState = { narrow: null, wide: null, error: errorMsg, initialized: false };
148-
149131
if (errorDiv) {
150132
errorDiv.textContent = errorMsg;
151133
errorDiv.style.display = 'block';
152134
}
153-
throw e;
154-
} finally {
155135
if (loadingDiv) loadingDiv.style.display = 'none';
136+
return { error: errorMsg };
156137
}
157138
}
158139
159-
// Convenience accessors that wait for initialization
160-
dbNarrow = initDatabases ? initDatabases.narrow : null
161-
dbWide = initDatabases ? initDatabases.wide : null
140+
dbNarrow = initDatabases && !initDatabases.error ? initDatabases.narrow : null
141+
dbWide = initDatabases && !initDatabases.error ? initDatabases.wide : null
162142
```
163143

164144
## Data Validity Check

0 commit comments

Comments
 (0)