Skip to content

fix(widget): move single-note widget query off the main thread#3251

Open
MiMoHo wants to merge 1 commit into
nextcloud:mainfrom
MiMoHo:fix/2935-single-note-widget-background-query
Open

fix(widget): move single-note widget query off the main thread#3251
MiMoHo wants to merge 1 commit into
nextcloud:mainfrom
MiMoHo:fix/2935-single-note-widget-background-query

Conversation

@MiMoHo

@MiMoHo MiMoHo commented Jul 3, 2026

Copy link
Copy Markdown

SingleNoteWidget.updateAppWidget() ran the blocking Room query NotesRepository.getSingleNoteWidgetData() synchronously inside the onReceive() / onUpdate() chain, i.e. on the main thread. This only works today because the Room database is built with allowMainThreadQueries() (NotesDatabase.java, already flagged with a // FIXME). A broadcast receiver doing disk I/O on the main thread risks jank or ANRs on slow storage.

Fix: the per-widget query and the subsequent RemoteViews update are now submitted to the provider's existing background executor — the same pattern onDeleted() already uses for removeSingleNoteWidget(). AppWidgetManager is safe to call from a background thread, so updateAppWidget() and notifyAppWidgetViewDataChanged() stay correct.

Fixes #2935

🏁 Checklist

  • ⛑️ Tests (unit and/or integration) are included or not needed
  • 🔙 Backport requests are created or not needed: /backport to stable-xx.x
  • 📅 Milestone is set
  • 🌸 PR title is meaningful (if it should be in the changelog: is it meaningful to users?)

🤖 AI (if applicable)

  • The content of this PR was fully generated using Claude Code: claude-fable-5

SingleNoteWidget.updateAppWidget() ran the blocking Room query
NotesRepository.getSingleNoteWidgetData() directly in the
onReceive()/onUpdate() call chain, i.e. on the main thread (this only
works at all because the database is configured with
allowMainThreadQueries()). Broadcast receivers should not perform disk
I/O on the main thread; on slow storage this risks jank or ANRs.

The per-widget query and RemoteViews update are now submitted to the
provider's existing background executor, the same pattern this class
already uses for removeSingleNoteWidget() in onDeleted().
AppWidgetManager is safe to call from a background thread.

Fixes nextcloud#2935

Assisted-by: Claude Code:claude-fable-5
AI-assistant: Claude Code 2.1.187 (Claude Fable 5)
Signed-off-by: MiMoHo <37556964+MiMoHo@users.noreply.github.com>
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

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.

SingleNoteWidget performs synchronous Room DB queries on main thread (may cause ANR/jank)

1 participant