Refines zap and report pruning.

This commit is contained in:
Vitor Pamplona
2023-08-29 17:24:48 -04:00
parent 217ed90d9a
commit 8b98efaad7
2 changed files with 55 additions and 35 deletions
@@ -1248,11 +1248,7 @@ object LocalCache {
} }
it.replyTo?.forEach { masterNote -> it.replyTo?.forEach { masterNote ->
masterNote.removeReply(it) removeLinkFromParentNote(it)
masterNote.removeBoost(it)
masterNote.removeReaction(it)
masterNote.removeZap(it)
masterNote.clearEOSE() // allows reloading of these events
} }
childrenToBeRemoved.addAll(it.removeAllChildNotes()) childrenToBeRemoved.addAll(it.removeAllChildNotes())
@@ -1274,6 +1270,7 @@ object LocalCache {
it.value.event is ReactionEvent || it.value.event is LnZapEvent || it.value.event is LnZapRequestEvent || it.value.event is ReactionEvent || it.value.event is LnZapEvent || it.value.event is LnZapRequestEvent ||
it.value.event is ReportEvent || it.value.event is GenericRepostEvent it.value.event is ReportEvent || it.value.event is GenericRepostEvent
) && ) &&
it.value.replyTo?.any { it.liveSet?.isInUse() == true } != true &&
it.value.liveSet?.isInUse() != true && // don't delete if observing. it.value.liveSet?.isInUse() != true && // don't delete if observing.
it.value.author?.pubkeyHex !in accounts && // don't delete if it is the logged in account it.value.author?.pubkeyHex !in accounts && // don't delete if it is the logged in account
it.value.event?.isTaggedUsers(accounts) != true // don't delete if it's a notification to the logged in user it.value.event?.isTaggedUsers(accounts) != true // don't delete if it's a notification to the logged in user
@@ -1284,25 +1281,36 @@ object LocalCache {
toBeRemoved.forEach { toBeRemoved.forEach {
notes.remove(it.idHex) notes.remove(it.idHex)
it.replyTo?.forEach { masterNote -> removeLinkFromParentNote(it)
masterNote.removeReply(it) removeAuthorLinkTo(it)
masterNote.removeBoost(it)
masterNote.removeReaction(it)
masterNote.removeZap(it)
masterNote.removeReport(it)
masterNote.clearEOSE() // allows reloading of these events
}
childrenToBeRemoved.addAll(it.removeAllChildNotes()) childrenToBeRemoved.addAll(it.removeAllChildNotes())
} }
removeChildrenOf(childrenToBeRemoved) removeChildrenOf(childrenToBeRemoved)
toBeRemoved.forEach {
it.replyTo?.forEach { masterNote ->
masterNote.clearEOSE() // allows reloading of these events
}
}
if (toBeRemoved.size > 1) { if (toBeRemoved.size > 1) {
println("PRUNE: ${toBeRemoved.size} thread replies removed.") println("PRUNE: ${toBeRemoved.size} thread replies removed.")
} }
} }
fun removeLinkFromParentNote(it: Note) {
it.replyTo?.forEach { masterNote ->
masterNote.removeReply(it)
masterNote.removeBoost(it)
masterNote.removeReaction(it)
masterNote.removeZap(it)
masterNote.removeReport(it)
masterNote.clearEOSE() // allows reloading of these events if needed
}
}
fun pruneExpiredEvents() { fun pruneExpiredEvents() {
checkNotInMainThread() checkNotInMainThread()
@@ -1315,14 +1323,8 @@ object LocalCache {
toBeRemoved.forEach { toBeRemoved.forEach {
notes.remove(it.idHex) notes.remove(it.idHex)
it.replyTo?.forEach { masterNote -> removeLinkFromParentNote(it)
masterNote.removeReply(it) removeAuthorLinkTo(it)
masterNote.removeBoost(it)
masterNote.removeReaction(it)
masterNote.removeZap(it)
masterNote.removeReport(it)
masterNote.clearEOSE() // allows reloading of these events
}
childrenToBeRemoved.addAll(it.removeAllChildNotes()) childrenToBeRemoved.addAll(it.removeAllChildNotes())
} }
@@ -1352,15 +1354,13 @@ object LocalCache {
toBeRemoved.forEach { toBeRemoved.forEach {
// Counts the replies // Counts the replies
it.replyTo?.forEach { masterNote -> it.replyTo?.forEach { masterNote ->
masterNote.removeReply(it) removeLinkFromParentNote(it)
masterNote.removeBoost(it)
masterNote.removeReaction(it)
masterNote.removeZap(it)
masterNote.removeReport(it)
} }
notes.remove(it.idHex) notes.remove(it.idHex)
removeAuthorLinkTo(it)
childrenToBeRemoved.addAll(it.removeAllChildNotes()) childrenToBeRemoved.addAll(it.removeAllChildNotes())
} }
@@ -1369,17 +1369,33 @@ object LocalCache {
println("PRUNE: ${toBeRemoved.size} messages removed because they were Hidden") println("PRUNE: ${toBeRemoved.size} messages removed because they were Hidden")
} }
fun removeChildrenOf(nextToBeRemoved: List<Note>) { fun removeAuthorLinkTo(note: Note) {
nextToBeRemoved.forEach { note ->
if (note.event is LnZapEvent) { if (note.event is LnZapEvent) {
(note.event as LnZapEvent).zappedAuthor().mapNotNull { getUserIfExists(it)?.removeZap(note) } (note.event as LnZapEvent).zappedAuthor().mapNotNull {
val author = getUserIfExists(it)
author?.removeZap(note)
author?.clearEOSE()
}
} }
if (note.event is LnZapRequestEvent) { if (note.event is LnZapRequestEvent) {
(note.event as LnZapRequestEvent).zappedAuthor().mapNotNull { getUserIfExists(it)?.removeZap(note) } (note.event as LnZapRequestEvent).zappedAuthor().mapNotNull {
val author = getUserIfExists(it)
author?.removeZap(note)
author?.clearEOSE()
}
} }
if (note.event is ReportEvent) { if (note.event is ReportEvent) {
(note.event as ReportEvent).reportedAuthor().mapNotNull { getUserIfExists(it.key)?.removeReport(note) } (note.event as ReportEvent).reportedAuthor().mapNotNull {
val author = getUserIfExists(it.key)
author?.removeReport(note)
author?.clearEOSE()
} }
}
}
fun removeChildrenOf(nextToBeRemoved: List<Note>) {
nextToBeRemoved.forEach { note ->
removeAuthorLinkTo(note)
notes.remove(note.idHex) notes.remove(note.idHex)
} }
} }
@@ -104,6 +104,10 @@ class User(val pubkeyHex: String) {
liveSet?.innerBookmarks?.invalidateData() liveSet?.innerBookmarks?.invalidateData()
} }
fun clearEOSE() {
latestEOSEs = emptyMap()
}
fun updateContactList(event: ContactListEvent) { fun updateContactList(event: ContactListEvent) {
if (event.id == latestContactList?.id) return if (event.id == latestContactList?.id) return