fix(widget): move single-note widget query off the main thread#3251
fix(widget): move single-note widget query off the main thread#3251MiMoHo 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.
|
Thanks, I will let CI run and then merge :tada |
|
Hello there, We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process. Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6 Thank you for contributing to Nextcloud and we hope to hear from you soon! (If you believe you should not receive this message, you can add yourself to the blocklist.) |
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)