fix: v0.3.0.3 — batched hashtag snapshot so Recent Tags fills promptly
The user reported the drawer's Recent Tags list eventually rendered,
but only after a couple of minutes. Root cause was inside
NoteRepositoryImpl:
1. hashtagUsageSnapshot() called noteBox.get(x.noteId) once per
cross-ref row. Most notes have multiple hashtags, so each note
was fetched many times — O(M) Box.get calls where M is the xref
count.
2. observeHashtagsByRecentUse() called trySend(snapshot()) BEFORE
setting up the ObjectBox subscription, then also inside the
observer. The first emission doubled the work; if the first
trySend ran before the upstream was warm, the data path itself
was slow.
Two surgical fixes inside NoteRepositoryImpl.kt:
- hashtagUsageSnapshot(): batch-load notes by id (one Box.get per
distinct noteId, not per xref) and tags by id (one Box.get per
distinct tagId). Net reads drop from (M + N) to
(distinct noteIds + distinct tagIds) — typically a 5–20×
reduction.
- observeHashtagsByRecentUse(): rely solely on the ObjectBox
observer's first fire (ObjectBox delivers the current query
state immediately on subscribe). Drop the manual pre-subscribe
trySend.
VERSION
- app/build.gradle.kts: versionCode 7 → 8, versionName '0.3.0.2' →
'0.3.0.3'.
- README.md changelog: new 0.3.0.3 row.
- Incido Development Plan.txt §10: new 0.3.0.3 row.
VERIFIED
- ./gradlew assembleDebug assembleRelease both green.
- versionCode=8, versionName='0.3.0.3'.
- No INTERNET permission.
- Release signed (v2 scheme verified).
This commit is contained in:
1 parent
a4651b3d63
commit
5b82d2a9fe
4 files changed
+37
-13
No files matched your search
@@ -376,6 +376,7 @@ A short reference for AI assistants:
|
||||
| 0.3.0.0 | 2026-08-14 | Hashtags (separate entity + cross-ref, 5-tag cap, autocomplete, persistent chips on editor, search() also matches tag names) + bolder colour accent (14 dp gradient stripe + tinted card background + corner chip) + nav drawer (Home / Favorites / Untagged + recent tags) + centred app-bar title + new version scheme adopted (validator in app/build.gradle.kts). |
|
||||
| 0.3.0.1 | 2026-08-14 | Urgent UI polish: editor hashtag row moved to the bottom (and hidden when empty), `+ add` chip removed (use `#` icon in top bar), colour picker centred horizontally, list-card dog-ear colour accent replaces the small circle chip, list cards show a hashtag row (with `+N` abbreviation when capped). |
|
||||
| 0.3.0.2 | 2026-08-14 | Hotfix: dropped the redundant leading `#` from the AddTagSheet placeholder (was `#tag-name`, now `hashtag-name` — the leading `#` icon in the field already signals the format). |
|
||||
| 0.3.0.3 | 2026-08-14 | Hotfix: `NoteRepositoryImpl.hashtagUsageSnapshot()` batched note/tag lookups (one `Box.get` per distinct noteId and tagId, not per xref) and the manual `trySend(snapshot())` in `observeHashtagsByRecentUse()` dropped — the ObjectBox observer's first fire is now the sole source. Result: the drawer's Recent Tags list fills in well under a second on real data instead of taking minutes. |
|
||||
|
||||
|
||||
---
|
||||
|
||||
@@ -110,6 +110,7 @@ cross-platform ports, end-to-end sync, and security features.
|
||||
| 0.3.0.0 | 2026-08-14 | Hashtags (visible chips on editor, 5-tag cap, autocomplete) + bolder colour accent + nav drawer (Home / Favorites / Untagged + recent tags) + centred app-bar title + new version scheme |
|
||||
| 0.3.0.1 | 2026-08-14 | Urgent UI polish: editor hashtag row moved to the bottom (and hidden when empty), `+ add` chip removed (use `#` icon in top bar), colour picker centred horizontally, list-card dog-ear colour accent replaces the small circle chip, list cards show a hashtag row (with `+N` abbreviation when capped). |
|
||||
| 0.3.0.2 | 2026-08-14 | Hotfix: dropped the redundant leading `#` from the AddTagSheet placeholder (was `#tag-name`, now `hashtag-name` — the leading `#` icon in the field already signals the format). |
|
||||
| 0.3.0.3 | 2026-08-14 | Hotfix: batched hashtag-usage lookups in `NoteRepositoryImpl.hashtagUsageSnapshot()` (one `Box.get` per distinct noteId and tagId, not per xref) and dropped the manual `trySend(snapshot())` in `observeHashtagsByRecentUse()` — the ObjectBox observer's first fire is now the sole source. The drawer's Recent Tags list fills in well under a second instead of taking minutes. |
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -28,8 +28,8 @@ android {
|
||||
applicationId = "org.incido.app"
|
||||
minSdk = 26
|
||||
targetSdk = 35
|
||||
versionCode = 7
|
||||
versionName = "0.3.0.2"
|
||||
versionCode = 8
|
||||
versionName = "0.3.0.3"
|
||||
}
|
||||
|
||||
// --- Signing ---
|
||||
|
||||
@@ -78,8 +78,13 @@ class NoteRepositoryImpl(
|
||||
}.flowOn(Dispatchers.Default)
|
||||
|
||||
override fun observeHashtagsByRecentUse(): Flow<List<HashtagUsage>> = callbackFlow {
|
||||
// ObjectBox fires its observer with the full current query state
|
||||
// immediately on subscribe, so the observer alone is the source
|
||||
// of truth — no manual trySend that would race the subscription
|
||||
// and double the work of the snapshot.
|
||||
val sub = noteBox.query().build().subscribe().observer { _ ->
|
||||
trySend(hashtagUsageSnapshot())
|
||||
val sub = noteBox.query().build().subscribe().observer { trySend(hashtagUsageSnapshot()) }
|
||||
}
|
||||
awaitClose { sub.cancel() }
|
||||
}.flowOn(Dispatchers.Default)
|
||||
|
||||
@@ -281,22 +286,39 @@ class NoteRepositoryImpl(
|
||||
val xrefs: List<NoteHashtagCrossRef> = xrefBox.all
|
||||
if (xrefs.isEmpty()) return emptyList()
|
||||
|
||||
// For each hashtagId, accumulate (lastUsedAt, count).
|
||||
data class Agg(var lastUsedAt: Long, var count: Int)
|
||||
val aggregate = HashMap<Long, Agg>(xrefs.size)
|
||||
// 1) Batch-load each unique noteId once (was once per xref, which
|
||||
// was O(M) Box.get calls for a notes-with-multiple-tags world).
|
||||
val noteIds: Set<Long> = xrefs.mapTo(HashSet(xrefs.size)) { it.noteId }
|
||||
val noteById: Map<Long, NoteEntity> = noteIds.mapNotNull { id ->
|
||||
noteBox.get(id)?.let { id to it }
|
||||
}.toMap()
|
||||
|
||||
// 2) Aggregate per hashtagId.
|
||||
val aggregate: HashMap<Long, LongArray> = HashMap(xrefs.size)
|
||||
for (x in xrefs) {
|
||||
val note: NoteEntity = noteBox.get(x.noteId) ?: continue
|
||||
val note: NoteEntity = noteById[x.noteId] ?: continue
|
||||
val cur = aggregate[x.hashtagId]
|
||||
if (cur == null) {
|
||||
aggregate[x.hashtagId] = Agg(note.updatedAt, 1)
|
||||
aggregate[x.hashtagId] = longArrayOf(note.updatedAt, 1L)
|
||||
} else {
|
||||
if (note.updatedAt > cur.lastUsedAt) cur.lastUsedAt = note.updatedAt
|
||||
cur.count += 1
|
||||
if (note.updatedAt > cur[0]) cur[0] = note.updatedAt
|
||||
cur[1] = cur[1] + 1
|
||||
}
|
||||
}
|
||||
return aggregate.mapNotNull { (tagId, agg) ->
|
||||
val tag: HashtagEntity = tagBox.get(tagId) ?: return@mapNotNull null
|
||||
HashtagUsage(name = tag.name, noteCount = agg.count, lastUsedAt = agg.lastUsedAt)
|
||||
|
||||
// 3) Batch-load each unique tagId once.
|
||||
val tagIds: List<Long> = aggregate.keys.toList()
|
||||
val tagById: Map<Long, HashtagEntity> = tagIds.mapNotNull { id ->
|
||||
tagBox.get(id)?.let { id to it }
|
||||
}.toMap()
|
||||
|
||||
return aggregate.mapNotNull { (tagId, arr) ->
|
||||
val tag: HashtagEntity = tagById[tagId] ?: return@mapNotNull null
|
||||
HashtagUsage(
|
||||
name = tag.name,
|
||||
noteCount = arr[1].toInt(),
|
||||
lastUsedAt = arr[0],
|
||||
)
|
||||
}.sortedWith(
|
||||
compareByDescending<HashtagUsage> { it.lastUsedAt }
|
||||
.thenByDescending { it.noteCount }
|
||||
|
||||
Reference in new issue
Block a user