mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-10-10 04:02:36 +02:00
Applying Memory trimming service to all logged in accounts.
This commit is contained in:
@@ -178,9 +178,6 @@ class AppModules(
|
|||||||
// Caches all events in Memory
|
// Caches all events in Memory
|
||||||
val cache: LocalCache = LocalCache
|
val cache: LocalCache = LocalCache
|
||||||
|
|
||||||
// Organizes cache clearing
|
|
||||||
val trimmingService = MemoryTrimmingService(cache)
|
|
||||||
|
|
||||||
// Provides a relay pool
|
// Provides a relay pool
|
||||||
val client: INostrClient = NostrClient(websocketBuilder, applicationDefaultScope)
|
val client: INostrClient = NostrClient(websocketBuilder, applicationDefaultScope)
|
||||||
|
|
||||||
@@ -215,6 +212,9 @@ class AppModules(
|
|||||||
client = client,
|
client = client,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Organizes cache clearing
|
||||||
|
val trimmingService = MemoryTrimmingService(cache)
|
||||||
|
|
||||||
// as new accounts are loaded, updates the state of the TorRelaySettings, which produces new TorRelayEvaluator
|
// as new accounts are loaded, updates the state of the TorRelaySettings, which produces new TorRelayEvaluator
|
||||||
// and reconnects relays if the configuration has been changed.
|
// and reconnects relays if the configuration has been changed.
|
||||||
val accountsTorStateConnector = AccountsTorStateConnector(accountsCache, torEvaluatorFlow, applicationDefaultScope)
|
val accountsTorStateConnector = AccountsTorStateConnector(accountsCache, torEvaluatorFlow, applicationDefaultScope)
|
||||||
@@ -283,7 +283,8 @@ class AppModules(
|
|||||||
|
|
||||||
fun trim() {
|
fun trim() {
|
||||||
applicationDefaultScope.launch {
|
applicationDefaultScope.launch {
|
||||||
trimmingService.run(null, LocalPreferences.allSavedAccounts())
|
val loggedIn = accountsCache.accounts.value.values
|
||||||
|
trimmingService.run(loggedIn, LocalPreferences.allSavedAccounts())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -43,7 +43,7 @@ abstract class Channel : NotesGatherer {
|
|||||||
fun changesFlow(): MutableSharedFlow<ListChange<Note>> {
|
fun changesFlow(): MutableSharedFlow<ListChange<Note>> {
|
||||||
val current = changesFlow.get()
|
val current = changesFlow.get()
|
||||||
if (current != null) return current
|
if (current != null) return current
|
||||||
val new = MutableSharedFlow<ListChange<Note>>(0, 100, BufferOverflow.DROP_OLDEST)
|
val new = MutableSharedFlow<ListChange<Note>>(0, 10, BufferOverflow.DROP_OLDEST)
|
||||||
changesFlow = WeakReference(new)
|
changesFlow = WeakReference(new)
|
||||||
return new
|
return new
|
||||||
}
|
}
|
||||||
|
@@ -33,13 +33,13 @@ class MemoryTrimmingService(
|
|||||||
var isTrimmingMemoryMutex = AtomicBoolean(false)
|
var isTrimmingMemoryMutex = AtomicBoolean(false)
|
||||||
|
|
||||||
private suspend fun doTrim(
|
private suspend fun doTrim(
|
||||||
account: Account? = null,
|
account: Collection<Account>,
|
||||||
otherAccounts: List<AccountInfo>,
|
otherAccounts: List<AccountInfo>,
|
||||||
) {
|
) {
|
||||||
cache.cleanMemory()
|
cache.cleanMemory()
|
||||||
cache.cleanObservers()
|
cache.cleanObservers()
|
||||||
|
|
||||||
account?.let {
|
account.forEach {
|
||||||
cache.pruneHiddenEvents(it)
|
cache.pruneHiddenEvents(it)
|
||||||
cache.pruneHiddenMessages(it)
|
cache.pruneHiddenMessages(it)
|
||||||
}
|
}
|
||||||
@@ -53,7 +53,7 @@ class MemoryTrimmingService(
|
|||||||
}
|
}
|
||||||
|
|
||||||
suspend fun run(
|
suspend fun run(
|
||||||
account: Account?,
|
account: Collection<Account>,
|
||||||
otherAccounts: List<AccountInfo>,
|
otherAccounts: List<AccountInfo>,
|
||||||
) {
|
) {
|
||||||
if (isTrimmingMemoryMutex.compareAndSet(false, true)) {
|
if (isTrimmingMemoryMutex.compareAndSet(false, true)) {
|
||||||
|
Reference in New Issue
Block a user