fix: correct better-sqlite3 pragma API usage for busy_timeout#140
Open
rohit-purandare wants to merge 2 commits intomainfrom
Open
fix: correct better-sqlite3 pragma API usage for busy_timeout#140rohit-purandare wants to merge 2 commits intomainfrom
rohit-purandare wants to merge 2 commits intomainfrom
Conversation
Fixed incorrect usage of the pragma() method when reading the busy_timeout
value. The old code was passing a boolean second parameter which is not
valid in the current better-sqlite3 API, causing "Expected second argument
to be an options object" errors in debug logs.
Changes:
- Updated pragma('busy_timeout', true) to pragma('busy_timeout')
- Changed property access from result[0].busy_timeout to result[0].timeout
(the pragma returns a 'timeout' property, not 'busy_timeout')
- Added comprehensive test suite for transaction timeout and pragma handling
The fix ensures:
- No more pragma API errors in debug logs
- Timeout values are correctly read and restored across transactions
- Transaction functionality continues to work as expected
Fixes the issue reported in logs:
"Could not set database timeout: Expected second argument to be an options object"
Fixed a critical bug where books with progress >= 95% (completion threshold) were being skipped by the early optimization even though they hadn't been marked as complete yet. This caused books at 99%+ progress to never get marked as finished. Root Cause: The early skip optimization (lines 617-647 and 759-788 in sync-manager.js) would return immediately when progress hadn't changed, without checking if the book needed completion processing. Books that were already above the 95% threshold but hadn't been marked complete were incorrectly skipped. Changes: - Modified early skip logic in both cache paths (identifier and title/author) - Added completion check: progress >= 95% AND no finished_at timestamp - Books meeting this criteria are no longer skipped; they proceed through normal flow to trigger completion detection - Books already marked complete (with finished_at) can still be safely skipped - Books below 95% progress continue to benefit from early skip optimization Test Coverage: - Unit tests: completion-early-skip-detection.test.js (10 tests) * Validates the exact bug scenario (99.77% unchanged progress) * Tests edge cases at completion boundary (94.99%, 95.0%, 95.01%) * Verifies behavior with and without finished_at timestamp - Integration tests: completion-early-skip-integration.test.js (8 tests) * Real-world sync scenarios across multiple syncs * Multiple books at various completion states * Title/author cache path verification * Edge cases and race conditions * Performance verification with 100 books The fix ensures: ✅ Books above completion threshold get marked as complete even when progress hasn't changed between syncs ✅ Already-completed books (with finished_at) are still optimized with early skip ✅ Books below 95% progress continue to benefit from performance optimization ✅ No performance impact on the optimization for non-completion cases ✅ Both ASIN/ISBN and title/author matching paths are covered Fixes issue where books showing "Early skip: Progress unchanged via cache (99.8%)" were never marked as completed despite being above the completion threshold.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixed incorrect usage of the pragma() method when reading the busy_timeout value. The old code was passing a boolean second parameter which is not valid in the current better-sqlite3 API, causing "Expected second argument to be an options object" errors in debug logs.
Changes:
The fix ensures:
Fixes the issue reported in logs:
"Could not set database timeout: Expected second argument to be an options object"