Repository navigation
再発見ウィジェットの更新は、ウィジェットを置いている間だけ、古い順の 30 件を出すのに要る列だけで DB を見るようにする - #101
Merged
Merged
Conversation
- RediscoverWidgetUpdater はアプリの起動からずっと、ウィジェットを置いていなくても、全件のブックマークを本文・タグごと読む 問い合わせ(getAllWithTags)を見ていた。ブックマーク・タグが変わるたび(AI 処理の段が進むたび、取り込みのたび)に全件を読み直していた - 置いているか(GlanceAppWidgetManager)を起動時に調べ、RediscoverWidgetReceiver の onEnabled・onDisabled で切り替える。置いていない間は DB を見ない - 候補は、最後に開いた日時が古い順の 30 件を、タイトル・出どころ・日時・アーカイブだけで読む(BookmarkDao.observeLeastRecentlyAccessed)。 「しばらく開いていない」で絞るのは並びの先頭からの範囲なので、選ばれるものは変わらない。ウィジェットの描画(provideGlance)も同じ読み方にする - 選ばれるものが同じことと、読み直し1回の時間を比べるテスト(RediscoverWidgetQueryPerformanceTest)、置いている間だけ見るテストを足した Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 15, 2026
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.
概要
「ときどきとても重くなる」の調査の2本目(1本目は #98)。再発見ウィジェットの更新が、ウィジェットを置いていなくても、ブックマークが変わるたびに全件を本文・タグごと読み直していたのを直す。
原因(根拠)
EchoMarkApplication.onCreateがRediscoverWidgetUpdater.start()を必ず呼び、アプリのプロセスが動いている間ずっとobserveBookmarks()=BookmarkDao.getAllWithTags()(SELECT * FROM bookmarks+ タグの関連)を見ていた。ウィジェットを置いていなくても見ていた(置いていないことは、読み直した後のupdateWidgetsで初めて調べていた)bookmarks・タグの表が変わるたびに問い合わせをやり直すため、AI 処理の段が進むたび(1件の処理で段の開始・本文・要約・タグ・終わりと何度も書く)、購読の新着の取り込みのたびに、全件の本文(取得したページの本文)を読み直していた変更内容
GlanceAppWidgetManager.getGlanceIdsで調べ、RediscoverWidgetReceiverのonEnabled(1つ目を置いた)・onDisabled(最後の1つを外した)で切り替える。置いていない間は DB を見ない(whilePlaced)。調べられなかったときは置いてあることにする(描き直しが止まらないように)BookmarkDao.observeLeastRecentlyAccessed(30):ORDER BY lastAccessedAt, id LIMIT 30で、id・種類・タイトル・URL・サイト名・ファイルの種類と大きさ・日時・アーカイブだけを読む(BookmarkSourceRow)。「しばらく開いていない」で絞るのは並びの先頭からの範囲なので、先に 30 件取ってから日時で絞っても、これまで(全件を日時で絞ってから 30 件)と同じものが選ばれる
RediscoverWidget.provideGlance。表示中のセッションの間 DB を見る)も同じ読み方にするBookmarkRepository.observeLeastRecentlyAccessedは、テスト用の Fake などのためにobserveBookmarks()から作る既定の実装を持つ測った結果
RediscoverWidgetQueryPerformanceTest(Robolectric): 5,000 件(本文 約 2,000 字・タグ 2 つ、1割はアーカイブ済み、最後に開いた日時はばらばら)getAllWithTags)observeLeastRecentlyAccessed(30))whilePlacedのテスト: 置いていない間は問い合わせを始めず、外したら止め、置き直したら1回だけ見直す)テスト
./gradlew :app:assembleDebug :app:testDebugUnitTest :app:lintDebug(絞り込みなし)を通した: 単体テスト 2,520 件・失敗 0(スキップ 4)、Lint の問題なし端末で確かめること(未検証)
onEnabled・onDisabledは端末のランチャーから呼ばれる)observeFiltered)・処理の状況(observeProcessingQueue)も本文ごと読み直している。これは次の PR で直す🤖 Generated with Claude Code