Skip to content

fix: reuse a single ZipFile per database during indexing instead of one per LOB - #637

Open
luis100 wants to merge 1 commit into
masterfrom
fix/636-mimetype-zipfile-reuse
Open

fix: reuse a single ZipFile per database during indexing instead of one per LOB#637
luis100 wants to merge 1 commit into
masterfrom
fix/636-mimetype-zipfile-reuse

Conversation

@luis100

@luis100 luis100 commented Jul 31, 2026

Copy link
Copy Markdown
Member

Summary

  • ToolkitStructure2ViewerStructure.detectMimeType() and getCLOBValue() opened a brand new ZipFile (re-reading the entire ZIP central directory) for every LOB cell in every row, making indexing O(N²) in row count for tables with LOB columns.
  • DbvtkExportModule now opens the SIARD ZipFile once in initDatabase(), threads it through getRowgetCellsgetCell into detectMimeType/getCLOBValue, and closes it once in finishDatabase(). If it can't be opened as a ZIP (e.g. SIARD-DK, which isn't ZIP-based), it falls back to the previous per-access ZipFile behavior so nothing regresses for those formats.
  • Also fixed a latent stream leak in detectMimeType's "blank file extension" fallback path (the previously-opened InputStream was never closed before being reassigned) and moved cleanup into a finally block so LOB streams/handles aren't left open when a shared ZipFile is now living across many calls.

Why

Fixes #636 — reported by @seso-kdrs: indexing a SIARD file with 25M rows and one LOB column (with ~800K ZIP entries) ran at ~10 rows/sec because the ZIP central directory was parsed millions of times. Reusing one ZipFile per database (instead of one per LOB) removes that redundant work while keeping MIME type auto-detection enabled.

Test plan

  • mvn test-compile succeeds
  • Manually verify indexing throughput improves on a SIARD file with many LOB rows (mime auto-detect enabled)
  • Verify SIARD-DK databases still index correctly (fallback path, no shared ZipFile)

…ne per LOB

detectMimeType() and getCLOBValue() opened a new ZipFile (re-reading the
whole ZIP central directory) for every LOB cell, making indexing O(N^2)
in row count. DbvtkExportModule now opens the SIARD ZipFile once in
initDatabase(), threads it through getRow/getCells/getCell into
detectMimeType/getCLOBValue for reuse, and closes it in finishDatabase().
Falls back to opening a ZipFile per LOB when no shared instance is
available (e.g. SIARD-DK, which isn't a ZIP file).

Fixes #636

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EqF9bUgRmnwnuSFCFjic1p
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. type: bug labels Jul 31, 2026
@luis100
luis100 requested a review from SugaryLump July 31, 2026 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files. type: bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

150x slowdown on indexing caused by mime detection

2 participants