fix(widget): move single-note widget query off the main thread#3251
Open
MiMoHo wants to merge 1 commit into
Open
fix(widget): move single-note widget query off the main thread#3251MiMoHo wants to merge 1 commit into
MiMoHo wants to merge 1 commit into
Conversation
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>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
| Duplication | 0 |
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.
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.
SingleNoteWidget.updateAppWidget()ran the blocking Room queryNotesRepository.getSingleNoteWidgetData()synchronously inside theonReceive()/onUpdate()chain, i.e. on the main thread. This only works today because the Room database is built withallowMainThreadQueries()(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
RemoteViewsupdate are now submitted to the provider's existing background executor — the same patternonDeleted()already uses forremoveSingleNoteWidget().AppWidgetManageris safe to call from a background thread, soupdateAppWidget()andnotifyAppWidgetViewDataChanged()stay correct.Fixes #2935
🏁 Checklist
/backport to stable-xx.x🤖 AI (if applicable)