Deletes encrypted component of the GiftWrap after unwrapping to avoid consuming memory needlessly
This commit is contained in:
+6
@@ -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)
|
||||
|
||||
+12
@@ -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)
|
||||
|
||||
+12
-7
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user