mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-09-28 19:07:09 +02:00
Improve cohesiveness of the pruning system.
This commit is contained in:
@@ -1183,13 +1183,7 @@ object LocalCache {
|
|||||||
val childrenToBeRemoved = mutableListOf<Note>()
|
val childrenToBeRemoved = mutableListOf<Note>()
|
||||||
|
|
||||||
toBeRemoved.forEach {
|
toBeRemoved.forEach {
|
||||||
notes.remove(it.idHex)
|
removeFromCache(it)
|
||||||
// Doesn't need to clean up the replies and mentions.. Too small to matter.
|
|
||||||
|
|
||||||
// Counts the replies
|
|
||||||
it.replyTo?.forEach { parent ->
|
|
||||||
parent.removeReply(it)
|
|
||||||
}
|
|
||||||
|
|
||||||
childrenToBeRemoved.addAll(it.removeAllChildNotes())
|
childrenToBeRemoved.addAll(it.removeAllChildNotes())
|
||||||
}
|
}
|
||||||
@@ -1208,12 +1202,7 @@ object LocalCache {
|
|||||||
val childrenToBeRemoved = mutableListOf<Note>()
|
val childrenToBeRemoved = mutableListOf<Note>()
|
||||||
|
|
||||||
toBeRemoved.forEach {
|
toBeRemoved.forEach {
|
||||||
notes.remove(it.idHex)
|
removeFromCache(it)
|
||||||
|
|
||||||
// Counts the replies
|
|
||||||
it.replyTo?.forEach { parent ->
|
|
||||||
parent.removeReply(it)
|
|
||||||
}
|
|
||||||
|
|
||||||
childrenToBeRemoved.addAll(it.removeAllChildNotes())
|
childrenToBeRemoved.addAll(it.removeAllChildNotes())
|
||||||
}
|
}
|
||||||
@@ -1240,17 +1229,12 @@ object LocalCache {
|
|||||||
val childrenToBeRemoved = mutableListOf<Note>()
|
val childrenToBeRemoved = mutableListOf<Note>()
|
||||||
|
|
||||||
toBeRemoved.forEach {
|
toBeRemoved.forEach {
|
||||||
notes.remove(it.idHex)
|
|
||||||
|
|
||||||
val newerVersion = addressables[(it.event as? AddressableEvent)?.address()?.toTag()]
|
val newerVersion = addressables[(it.event as? AddressableEvent)?.address()?.toTag()]
|
||||||
if (newerVersion != null) {
|
if (newerVersion != null) {
|
||||||
it.moveAllReferencesTo(newerVersion)
|
it.moveAllReferencesTo(newerVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
it.replyTo?.forEach { masterNote ->
|
removeFromCache(it)
|
||||||
removeLinkFromParentNote(it)
|
|
||||||
}
|
|
||||||
|
|
||||||
childrenToBeRemoved.addAll(it.removeAllChildNotes())
|
childrenToBeRemoved.addAll(it.removeAllChildNotes())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1279,11 +1263,7 @@ object LocalCache {
|
|||||||
val childrenToBeRemoved = mutableListOf<Note>()
|
val childrenToBeRemoved = mutableListOf<Note>()
|
||||||
|
|
||||||
toBeRemoved.forEach {
|
toBeRemoved.forEach {
|
||||||
notes.remove(it.idHex)
|
removeFromCache(it)
|
||||||
|
|
||||||
removeLinkFromParentNote(it)
|
|
||||||
removeAuthorLinkTo(it)
|
|
||||||
|
|
||||||
childrenToBeRemoved.addAll(it.removeAllChildNotes())
|
childrenToBeRemoved.addAll(it.removeAllChildNotes())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1300,73 +1280,39 @@ object LocalCache {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun removeLinkFromParentNote(it: Note) {
|
private fun removeFromCache(note: Note) {
|
||||||
it.replyTo?.forEach { masterNote ->
|
note.replyTo?.forEach { masterNote ->
|
||||||
masterNote.removeReply(it)
|
masterNote.removeReply(note)
|
||||||
masterNote.removeBoost(it)
|
masterNote.removeBoost(note)
|
||||||
masterNote.removeReaction(it)
|
masterNote.removeReaction(note)
|
||||||
masterNote.removeZap(it)
|
masterNote.removeZap(note)
|
||||||
masterNote.removeReport(it)
|
masterNote.removeReport(note)
|
||||||
masterNote.clearEOSE() // allows reloading of these events if needed
|
masterNote.clearEOSE() // allows reloading of these events if needed
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fun pruneExpiredEvents() {
|
if (note.event is LnZapEvent) {
|
||||||
checkNotInMainThread()
|
(note.event as LnZapEvent).zappedAuthor().mapNotNull {
|
||||||
|
val author = getUserIfExists(it)
|
||||||
val toBeRemoved = notes.filter {
|
author?.removeZap(note)
|
||||||
it.value.event?.isExpired() == true
|
author?.clearEOSE()
|
||||||
}.values
|
}
|
||||||
|
}
|
||||||
val childrenToBeRemoved = mutableListOf<Note>()
|
if (note.event is LnZapRequestEvent) {
|
||||||
|
(note.event as LnZapRequestEvent).zappedAuthor().mapNotNull {
|
||||||
toBeRemoved.forEach {
|
val author = getUserIfExists(it)
|
||||||
notes.remove(it.idHex)
|
author?.removeZap(note)
|
||||||
|
author?.clearEOSE()
|
||||||
removeLinkFromParentNote(it)
|
}
|
||||||
removeAuthorLinkTo(it)
|
}
|
||||||
|
if (note.event is ReportEvent) {
|
||||||
childrenToBeRemoved.addAll(it.removeAllChildNotes())
|
(note.event as ReportEvent).reportedAuthor().mapNotNull {
|
||||||
}
|
val author = getUserIfExists(it.key)
|
||||||
|
author?.removeReport(note)
|
||||||
removeChildrenOf(childrenToBeRemoved)
|
author?.clearEOSE()
|
||||||
|
|
||||||
if (toBeRemoved.size > 1) {
|
|
||||||
println("PRUNE: ${toBeRemoved.size} thread replies removed.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun pruneHiddenMessages(account: Account) {
|
|
||||||
checkNotInMainThread()
|
|
||||||
|
|
||||||
val childrenToBeRemoved = mutableListOf<Note>()
|
|
||||||
|
|
||||||
val toBeRemoved = account.hiddenUsers.map { userHex ->
|
|
||||||
(
|
|
||||||
notes.values.filter {
|
|
||||||
it.event?.pubKey() == userHex
|
|
||||||
} + addressables.values.filter {
|
|
||||||
it.event?.pubKey() == userHex
|
|
||||||
}
|
|
||||||
).toSet()
|
|
||||||
}.flatten()
|
|
||||||
|
|
||||||
toBeRemoved.forEach {
|
|
||||||
// Counts the replies
|
|
||||||
it.replyTo?.forEach { masterNote ->
|
|
||||||
removeLinkFromParentNote(it)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
notes.remove(it.idHex)
|
|
||||||
|
|
||||||
removeAuthorLinkTo(it)
|
|
||||||
|
|
||||||
childrenToBeRemoved.addAll(it.removeAllChildNotes())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
removeChildrenOf(childrenToBeRemoved)
|
notes.remove(note.idHex)
|
||||||
|
|
||||||
println("PRUNE: ${toBeRemoved.size} messages removed because they were Hidden")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun removeAuthorLinkTo(note: Note) {
|
fun removeAuthorLinkTo(note: Note) {
|
||||||
@@ -1395,11 +1341,56 @@ object LocalCache {
|
|||||||
|
|
||||||
fun removeChildrenOf(nextToBeRemoved: List<Note>) {
|
fun removeChildrenOf(nextToBeRemoved: List<Note>) {
|
||||||
nextToBeRemoved.forEach { note ->
|
nextToBeRemoved.forEach { note ->
|
||||||
removeAuthorLinkTo(note)
|
removeFromCache(note)
|
||||||
notes.remove(note.idHex)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun pruneExpiredEvents() {
|
||||||
|
checkNotInMainThread()
|
||||||
|
|
||||||
|
val toBeRemoved = notes.filter {
|
||||||
|
it.value.event?.isExpired() == true
|
||||||
|
}.values
|
||||||
|
|
||||||
|
val childrenToBeRemoved = mutableListOf<Note>()
|
||||||
|
|
||||||
|
toBeRemoved.forEach {
|
||||||
|
removeFromCache(it)
|
||||||
|
childrenToBeRemoved.addAll(it.removeAllChildNotes())
|
||||||
|
}
|
||||||
|
|
||||||
|
removeChildrenOf(childrenToBeRemoved)
|
||||||
|
|
||||||
|
if (toBeRemoved.size > 1) {
|
||||||
|
println("PRUNE: ${toBeRemoved.size} thread replies removed.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun pruneHiddenMessages(account: Account) {
|
||||||
|
checkNotInMainThread()
|
||||||
|
|
||||||
|
val childrenToBeRemoved = mutableListOf<Note>()
|
||||||
|
|
||||||
|
val toBeRemoved = account.hiddenUsers.map { userHex ->
|
||||||
|
(
|
||||||
|
notes.values.filter {
|
||||||
|
it.event?.pubKey() == userHex
|
||||||
|
} + addressables.values.filter {
|
||||||
|
it.event?.pubKey() == userHex
|
||||||
|
}
|
||||||
|
).toSet()
|
||||||
|
}.flatten()
|
||||||
|
|
||||||
|
toBeRemoved.forEach {
|
||||||
|
removeFromCache(it)
|
||||||
|
childrenToBeRemoved.addAll(it.removeAllChildNotes())
|
||||||
|
}
|
||||||
|
|
||||||
|
removeChildrenOf(childrenToBeRemoved)
|
||||||
|
|
||||||
|
println("PRUNE: ${toBeRemoved.size} messages removed because they were Hidden")
|
||||||
|
}
|
||||||
|
|
||||||
fun pruneContactLists(loggedIn: Set<HexKey>) {
|
fun pruneContactLists(loggedIn: Set<HexKey>) {
|
||||||
checkNotInMainThread()
|
checkNotInMainThread()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user