-
Notifications
You must be signed in to change notification settings - Fork 10
fix(native): enable bulkInsertNodes native path #736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
8adc1d4
0f3cb1e
50c4a7b
6d39ef7
ad6e24c
fcf94b1
3ac9cc7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -736,13 +736,21 @@ impl NativeDatabase { | |
| /// Bulk-insert nodes, children, containment edges, exports, and file hashes. | ||
| /// Reuses the persistent connection instead of opening a new one. | ||
| /// Returns `true` on success, `false` on failure. | ||
| #[napi] | ||
| /// | ||
| /// Batches are received as `serde_json::Value` and deserialized via serde so | ||
| /// that `null` visibility values map to `None` instead of crashing napi's | ||
| /// `Option<String>` object conversion (#709). | ||
| #[napi(ts_args_type = "batches: InsertNodesBatch[], fileHashes: FileHashEntry[], removedFiles: string[]")] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
// generated .d.ts would have:
bulkInsertNodes(batches: InsertNodesBatch[], fileHashes: FileHashEntry[], removedFiles: string[]): boolean
// but InsertNodesBatch would not be declared → TypeScript errorThe CI item "CI validates Rust crate compilation" is unchecked, so the generated Consider either re-adding
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 50c4a7b. Two changes:
|
||
| pub fn bulk_insert_nodes( | ||
| &self, | ||
| batches: Vec<InsertNodesBatch>, | ||
| batches: serde_json::Value, | ||
| file_hashes: Vec<FileHashEntry>, | ||
| removed_files: Vec<String>, | ||
| ) -> napi::Result<bool> { | ||
| let batches: Vec<InsertNodesBatch> = serde_json::from_value(batches) | ||
| .map_err(|e| { | ||
| napi::Error::from_reason(format!("bulk_insert_nodes: invalid batches: {e}")) | ||
| })?; | ||
| let conn = self.conn()?; | ||
| Ok(insert_nodes::do_insert_nodes(conn, &batches, &file_hashes, &removed_files) | ||
| .inspect_err(|e| eprintln!("[NativeDatabase] bulk_insert_nodes failed: {e}")) | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -223,7 +223,33 @@ async function runPipelineStages(ctx: PipelineContext): Promise<void> { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| if (ctx.earlyExit) return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| await parseFiles(ctx); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Temporarily reopen nativeDb for insertNodes — it uses the WAL checkpoint | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| // guard internally (same pattern as feature modules). Closed again before | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| // resolveImports/buildEdges which don't yet have the guard (#709). | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (hadNativeDb && ctx.engineName === 'native') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const native = loadNative(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (native?.NativeDatabase) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ctx.nativeDb = native.NativeDatabase.openReadWrite(ctx.dbPath); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ctx.nativeDb = undefined; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| await insertNodes(ctx); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Close nativeDb after insertNodes — remaining pipeline stages use JS paths. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (ctx.nativeDb && ctx.db) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ctx.nativeDb.close(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| /* ignore close errors */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ctx.nativeDb = undefined; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+243
to
+269
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
After Every other
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 0f3cb1e. Added the WAL checkpoint (TRUNCATE) before close, matching the pattern at lines 199-212 and 281-294 in the same file. This was indeed causing the |
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| await resolveImports(ctx); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| await buildEdges(ctx); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| await buildStructure(ctx); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
childrenfield lacks#[serde(default)]for defensive deserializationend_lineandvisibilityon bothInsertNodesDefinitionandInsertNodesChildcorrectly use#[serde(default)]to tolerate missing fields, butchildren: Vec<InsertNodesChild>onInsertNodesDefinitiondoes not. If a future caller or extractor omits thechildrenkey entirely (instead of sending[]), serde would return a deserialization error, surfaced as a napi error from the?inserde_json::from_value. The JS side currently always populateschildren(via(def.children ?? []).map(...)) but adding the attribute maintains the same defensive pattern used for the optional fields:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 50c4a7b. Added
#[serde(default)]toInsertNodesDefinition.children, consistent with the defensive pattern on the other optional fields.