diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/notifications/EventNotificationConsumer.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/notifications/EventNotificationConsumer.kt index f4e1a2a58..5192603b9 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/notifications/EventNotificationConsumer.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/notifications/EventNotificationConsumer.kt @@ -177,6 +177,9 @@ class EventNotificationConsumer( if (LocalCache.justConsume(event, null)) { // new event event.unwrap(signer) { + // clear the encrypted payload to save memory + LocalCache.getOrCreateNote(event.id).event = event.copyNoContent() + unwrapAndConsume(it, signer, onReady) } } @@ -185,6 +188,9 @@ class EventNotificationConsumer( if (LocalCache.justConsume(event, null)) { // new event event.unseal(signer) { + // clear the encrypted payload to save memory + LocalCache.getOrCreateNote(event.id).event = event.copyNoContent() + // this is not verifiable if (!LocalCache.hasConsumed(it)) { LocalCache.justConsume(it, null) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt index 27ea31fe3..907598faa 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt @@ -1466,6 +1466,9 @@ class AccountViewModel( unwrapIfNeeded(existingNote.event, onReady) } else { event.unwrap(account.signer) { + // clear the encrypted payload to save memory + LocalCache.getOrCreateNote(event.id).event = event.copyNoContent() + if (LocalCache.justConsume(it, null)) { unwrapIfNeeded(it, onReady) } @@ -1473,6 +1476,9 @@ class AccountViewModel( } } ?: run { event.unwrap(account.signer) { + // clear the encrypted payload to save memory + LocalCache.getOrCreateNote(event.id).event = event.copyNoContent() + val existingNote = LocalCache.getNoteIfExists(it.id) if (existingNote != null) { unwrapIfNeeded(existingNote.event, onReady) @@ -1491,6 +1497,9 @@ class AccountViewModel( unwrapIfNeeded(existingNote.event, onReady) } else { event.unseal(account.signer) { + // clear the encrypted payload to save memory + LocalCache.getOrCreateNote(event.id).event = event.copyNoContent() + // this is not verifiable if (LocalCache.justConsume(it, null)) { unwrapIfNeeded(it, onReady) @@ -1499,6 +1508,9 @@ class AccountViewModel( } } ?: run { event.unseal(account.signer) { + // clear the encrypted payload to save memory + LocalCache.getOrCreateNote(event.id).event = event.copyNoContent() + val existingNote = LocalCache.getNoteIfExists(it.id) if (existingNote != null) { unwrapIfNeeded(existingNote.event, onReady) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/PrecacheNewNotesProcessor.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/PrecacheNewNotesProcessor.kt index 8a6458d74..fdc392fd1 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/PrecacheNewNotesProcessor.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/PrecacheNewNotesProcessor.kt @@ -52,7 +52,7 @@ class PrecacheNewNotesProcessor( fun consumeAlreadyVerified( event: Event, - note: Note, + publicNote: Note, ) { when (event) { is OtsEvent -> { @@ -78,16 +78,18 @@ class PrecacheNewNotesProcessor( val inner = event.innerEventId if (inner == null) { event.unwrap(account.signer) { + // clear the encrypted payload to save memory + cache.getOrCreateNote(event.id).event = event.copyNoContent() if (cache.justConsume(it, null)) { - cache.copyRelaysFromTo(note, it) - consumeAlreadyVerified(it, note) + cache.copyRelaysFromTo(publicNote, it) + consumeAlreadyVerified(it, publicNote) } } } else { - cache.copyRelaysFromTo(note, inner) + cache.copyRelaysFromTo(publicNote, inner) val event = cache.getOrCreateNote(inner).event if (event != null) { - consumeAlreadyVerified(event, note) + consumeAlreadyVerified(event, publicNote) } } } @@ -97,11 +99,14 @@ class PrecacheNewNotesProcessor( val inner = event.innerEventId if (inner == null) { event.unseal(account.signer) { + // clear the encrypted payload to save memory + cache.getOrCreateNote(event.id).event = event.copyNoContent() + cache.justConsume(it, null) - cache.copyRelaysFromTo(note, it) + cache.copyRelaysFromTo(publicNote, it) } } else { - cache.copyRelaysFromTo(note, inner) + cache.copyRelaysFromTo(publicNote, inner) } }