From a29d9ad433afccbd04f8b9c0c51234336135845e Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Tue, 23 May 2023 10:37:18 -0400 Subject: [PATCH] Adds a cache layer for citations in Notes --- .../amethyst/service/model/BaseTextNoteEvent.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/service/model/BaseTextNoteEvent.kt b/app/src/main/java/com/vitorpamplona/amethyst/service/model/BaseTextNoteEvent.kt index 93f576f05..4f9e98fce 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/service/model/BaseTextNoteEvent.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/service/model/BaseTextNoteEvent.kt @@ -19,6 +19,7 @@ open class BaseTextNoteEvent( open fun replyTos() = tags.filter { it.firstOrNull() == "e" }.mapNotNull { it.getOrNull(1) } private var citedUsersCache: Set? = null + private var citedNotesCache: Set? = null fun citedUsers(): Set { citedUsersCache?.let { return it } @@ -61,8 +62,10 @@ open class BaseTextNoteEvent( return returningList } - fun findCitations(): Set { - var citations = mutableSetOf() + fun findCitations(): Set { + citedNotesCache?.let { return it } + + val citations = mutableSetOf() // Removes citations from replies: val matcher = tagSearch.matcher(content) while (matcher.find()) { @@ -102,6 +105,7 @@ open class BaseTextNoteEvent( } } + citedNotesCache = citations return citations }