Refactors thread assembler to reduce number of lists used.

This commit is contained in:
Vitor Pamplona
2023-02-18 19:07:16 -05:00
parent d2c39b022b
commit 89f714b1ad
@@ -37,12 +37,11 @@ class ThreadAssembler {
val note = LocalCache.getOrCreateNote(noteId) val note = LocalCache.getOrCreateNote(noteId)
if (note.event != null) { if (note.event != null) {
val thread = mutableListOf<Note>() val thread = mutableSetOf<Note>()
val threadSet = mutableSetOf<Note>()
val threadRoot = searchRoot(note) ?: note val threadRoot = searchRoot(note, thread) ?: note
loadDown(threadRoot, thread, threadSet) loadDown(threadRoot, thread)
thread.toSet() thread.toSet()
} else { } else {
@@ -55,13 +54,12 @@ class ThreadAssembler {
return result return result
} }
fun loadDown(note: Note, thread: MutableList<Note>, threadSet: MutableSet<Note>) { fun loadDown(note: Note, thread: MutableSet<Note>) {
if (note !in threadSet) { if (note !in thread) {
thread.add(note) thread.add(note)
threadSet.add(note)
note.replies.forEach { note.replies.forEach {
loadDown(it, thread, threadSet) loadDown(it, thread)
} }
} }
} }