Skip to content

Chunk sync-status IDs to stay under SQLite's variable limit#2188

Open
mjhfunctionalashtanga wants to merge 1 commit into
jocmp:mainfrom
mjhfunctionalashtanga:fix/sync-status-sqlite-variable-limit
Open

Chunk sync-status IDs to stay under SQLite's variable limit#2188
mjhfunctionalashtanga wants to merge 1 commit into
jocmp:mainfrom
mjhfunctionalashtanga:fix/sync-status-sqlite-variable-limit

Conversation

@mjhfunctionalashtanga

Copy link
Copy Markdown

Problem

On an account with a large backlog of queued read/unread changes, the app crashes on every sync (so it never recovers):

android.database.sqlite.SQLiteException: too many SQL variables (code 1 SQLITE_ERROR):
DELETE FROM article_sync_statuses WHERE selected = 1 AND article_id IN (?,?,… >999 …) AND "key" = ?
    at com.jocmp.capy.db.ArticleSyncStatusQueries.deleteSelectedByID
    at com.jocmp.capy.persistence.SyncStatusRecords.deleteSelected
    at com.jocmp.capy.Account.dispatch

Account.dispatch pushes the queued status changes, then calls SyncStatusRecords.deleteSelected(ids, key) / resetSelected(ids, key), which pass the entire ID list into a single IN (…) clause. SQLite's SQLITE_MAX_VARIABLE_NUMBER is 999 on the engine bundled with Android (< 3.32), so once more than ~999 changes are queued the statement won't even compile and the app hard-crashes.

Fix

Chunk the ID list into batches of 500 (well under the limit, leaving headroom for the key bind param) inside a transaction — matching the chunking already used by Account.markAllRead and ArticleRecords.dismissNotifications.

Reproduced and verified on a Boox device (Android 11) with a ~2,700-entry Miniflux account: the crash is gone and the backlog drains cleanly.

🤖 Generated with Claude Code

https://claude.ai/code/session_015yVKgdxd3ZSrFeY5eWpFuA

Account.dispatch calls SyncStatusRecords.deleteSelected/resetSelected with the entire queued ID list in one IN(...) clause. SQLite caps bound variables at 999 on the Android-bundled engine (< 3.32), so on a large backlog the statement fails to compile ("too many SQL variables") and the app hard-crashes on every sync until the queue is cleared. Chunk the IDs into batches of 500 within a transaction, matching the existing chunking in Account.markAllRead and ArticleRecords.dismissNotifications.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015yVKgdxd3ZSrFeY5eWpFuA
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant