Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/book-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,8 @@ export class BookCache {
let originalBusyTimeout;
try {
// Get current busy timeout and set a new one
originalBusyTimeout = this.db.pragma('busy_timeout', true);
const result = this.db.pragma('busy_timeout');
originalBusyTimeout = result[0]?.timeout;
this.db.pragma(`busy_timeout = ${timeout}`);
} catch (error) {
logger.debug(`Could not set database timeout: ${error.message}`);
Expand Down
79 changes: 58 additions & 21 deletions src/sync-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -615,16 +615,35 @@ export class SyncManager {
);

if (!progressChanged) {
hasChanged = false;
cacheFoundEarly = true;
logger.debug(
`Early skip for ${title}: Progress unchanged via ${type} cache (${validatedProgress.toFixed(1)}%)`,
{
cacheKey: key,
cacheType: type,
editionId: cachedInfo.edition_id,
},
);
// Check if book needs completion processing even though progress hasn't changed
const needsCompletionProcessing =
validatedProgress >= 95 && !cachedInfo.finished_at;

if (needsCompletionProcessing) {
logger.debug(
`${title}: Progress unchanged but needs completion processing (${validatedProgress.toFixed(1)}%, no finished_at)`,
{
cacheKey: key,
cacheType: type,
editionId: cachedInfo.edition_id,
progress: validatedProgress,
finishedAt: cachedInfo.finished_at,
},
);
// Don't skip - let it go through normal flow for completion detection
hasChanged = true; // Force processing
} else {
hasChanged = false;
cacheFoundEarly = true;
logger.debug(
`Early skip for ${title}: Progress unchanged via ${type} cache (${validatedProgress.toFixed(1)}%)`,
{
cacheKey: key,
cacheType: type,
editionId: cachedInfo.edition_id,
},
);
}
break;
} else {
logger.debug(
Expand Down Expand Up @@ -738,17 +757,35 @@ export class SyncManager {
);

if (!titleAuthorProgressChanged) {
hasChanged = false;
cacheFoundEarly = true;
shouldPerformExpensiveMatching = false; // Skip expensive matching entirely
logger.debug(
`Early skip for ${title}: Progress unchanged via title/author cache (${validatedProgress.toFixed(1)}%)`,
{
cachePattern: bestCachePattern,
editionId: bestCacheMatch.edition_id,
cachedProgress: bestCacheMatch.progress_percent,
},
);
// Check if book needs completion processing even though progress hasn't changed
const needsCompletionProcessing =
validatedProgress >= 95 && !bestCacheMatch.finished_at;

if (needsCompletionProcessing) {
logger.debug(
`${title}: Progress unchanged but needs completion processing (${validatedProgress.toFixed(1)}%, no finished_at)`,
{
cachePattern: bestCachePattern,
editionId: bestCacheMatch.edition_id,
progress: validatedProgress,
finishedAt: bestCacheMatch.finished_at,
},
);
// Don't skip - let it go through normal flow for completion detection
hasChanged = true; // Force processing
} else {
hasChanged = false;
cacheFoundEarly = true;
shouldPerformExpensiveMatching = false; // Skip expensive matching entirely
logger.debug(
`Early skip for ${title}: Progress unchanged via title/author cache (${validatedProgress.toFixed(1)}%)`,
{
cachePattern: bestCachePattern,
editionId: bestCacheMatch.edition_id,
cachedProgress: bestCacheMatch.progress_percent,
},
);
}
} else {
logger.debug(
`Title/author book ${title}: Progress changed (${bestCacheMatch.progress_percent}% → ${validatedProgress.toFixed(1)}%) - proceeding with sync`,
Expand Down
Loading