mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-10-11 01:13:35 +02:00
Moves heavy computations away from IO
This commit is contained in:
@@ -378,7 +378,7 @@ class AccountViewModel(
|
|||||||
onZapAmount: (String) -> Unit,
|
onZapAmount: (String) -> Unit,
|
||||||
) {
|
) {
|
||||||
if (zappedNote.zapPayments.isNotEmpty()) {
|
if (zappedNote.zapPayments.isNotEmpty()) {
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.Default) {
|
||||||
account.calculateZappedAmount(zappedNote) { onZapAmount(showAmount(it)) }
|
account.calculateZappedAmount(zappedNote) { onZapAmount(showAmount(it)) }
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -392,7 +392,7 @@ class AccountViewModel(
|
|||||||
) {
|
) {
|
||||||
val zapraiserAmount = zappedNote.event?.zapraiserAmount() ?: 0
|
val zapraiserAmount = zappedNote.event?.zapraiserAmount() ?: 0
|
||||||
if (zappedNote.zapPayments.isNotEmpty()) {
|
if (zappedNote.zapPayments.isNotEmpty()) {
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.Default) {
|
||||||
account.calculateZappedAmount(zappedNote) { newZapAmount ->
|
account.calculateZappedAmount(zappedNote) { newZapAmount ->
|
||||||
var percentage = newZapAmount.div(zapraiserAmount.toBigDecimal()).toFloat()
|
var percentage = newZapAmount.div(zapraiserAmount.toBigDecimal()).toFloat()
|
||||||
|
|
||||||
@@ -1049,9 +1049,11 @@ class AccountViewModel(
|
|||||||
note: Note,
|
note: Note,
|
||||||
onResult: (Long?) -> Unit,
|
onResult: (Long?) -> Unit,
|
||||||
) {
|
) {
|
||||||
withContext(Dispatchers.IO) {
|
onResult(
|
||||||
onResult(LocalCache.findEarliestOtsForNote(note))
|
withContext(Dispatchers.Default) {
|
||||||
}
|
LocalCache.findEarliestOtsForNote(note)
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun cachedModificationEventsForNote(note: Note) = LocalCache.cachedModificationEventsForNote(note)
|
fun cachedModificationEventsForNote(note: Note) = LocalCache.cachedModificationEventsForNote(note)
|
||||||
@@ -1060,9 +1062,11 @@ class AccountViewModel(
|
|||||||
note: Note,
|
note: Note,
|
||||||
onResult: (List<Note>) -> Unit,
|
onResult: (List<Note>) -> Unit,
|
||||||
) {
|
) {
|
||||||
withContext(Dispatchers.IO) {
|
onResult(
|
||||||
onResult(LocalCache.findLatestModificationForNote(note))
|
withContext(Dispatchers.Default) {
|
||||||
}
|
LocalCache.findLatestModificationForNote(note)
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun checkGetOrCreateChannel(key: HexKey): Channel? = LocalCache.checkGetOrCreateChannel(key)
|
private suspend fun checkGetOrCreateChannel(key: HexKey): Channel? = LocalCache.checkGetOrCreateChannel(key)
|
||||||
@@ -1547,7 +1551,7 @@ class AccountViewModel(
|
|||||||
is Nip19Bech32.Note -> withContext(Dispatchers.IO) { LocalCache.checkGetOrCreateNote(parsed.hex)?.let { note -> returningNote = note } }
|
is Nip19Bech32.Note -> withContext(Dispatchers.IO) { LocalCache.checkGetOrCreateNote(parsed.hex)?.let { note -> returningNote = note } }
|
||||||
is Nip19Bech32.NEvent -> withContext(Dispatchers.IO) { LocalCache.checkGetOrCreateNote(parsed.hex)?.let { note -> returningNote = note } }
|
is Nip19Bech32.NEvent -> withContext(Dispatchers.IO) { LocalCache.checkGetOrCreateNote(parsed.hex)?.let { note -> returningNote = note } }
|
||||||
is Nip19Bech32.NEmbed ->
|
is Nip19Bech32.NEmbed ->
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.Default) {
|
||||||
val baseNote = LocalCache.getOrCreateNote(parsed.event)
|
val baseNote = LocalCache.getOrCreateNote(parsed.event)
|
||||||
if (baseNote.event == null) {
|
if (baseNote.event == null) {
|
||||||
launch(Dispatchers.IO) {
|
launch(Dispatchers.IO) {
|
||||||
|
Reference in New Issue
Block a user