Adds zap amount cache for the memory space calculations
This commit is contained in:
@@ -39,9 +39,20 @@ class LnZapEvent(
|
|||||||
// This event is also kept in LocalCache (same object)
|
// This event is also kept in LocalCache (same object)
|
||||||
@Transient val zapRequest: LnZapRequestEvent?
|
@Transient val zapRequest: LnZapRequestEvent?
|
||||||
|
|
||||||
|
// Keeps this as a field because it's a heavier function used everywhere.
|
||||||
|
val amount by lazy {
|
||||||
|
try {
|
||||||
|
lnInvoice()?.let { LnInvoiceUtil.getAmountInSats(it) }
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e("LnZapEvent", "Failed to Parse LnInvoice ${lnInvoice()}", e)
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun countMemory(): Long =
|
override fun countMemory(): Long =
|
||||||
super.countMemory() +
|
super.countMemory() +
|
||||||
pointerSizeInBytes + (zapRequest?.countMemory() ?: 0) // rough calculation
|
pointerSizeInBytes + (zapRequest?.countMemory() ?: 0) + // rough calculation
|
||||||
|
pointerSizeInBytes + 36 // bigdecimal size
|
||||||
|
|
||||||
override fun containedPost(): LnZapRequestEvent? =
|
override fun containedPost(): LnZapRequestEvent? =
|
||||||
try {
|
try {
|
||||||
@@ -75,16 +86,6 @@ class LnZapEvent(
|
|||||||
|
|
||||||
override fun amount() = amount
|
override fun amount() = amount
|
||||||
|
|
||||||
// Keeps this as a field because it's a heavier function used everywhere.
|
|
||||||
val amount by lazy {
|
|
||||||
try {
|
|
||||||
lnInvoice()?.let { LnInvoiceUtil.getAmountInSats(it) }
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Log.e("LnZapEvent", "Failed to Parse LnInvoice ${lnInvoice()}", e)
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun content(): String = content
|
override fun content(): String = content
|
||||||
|
|
||||||
fun lnInvoice() = tags.firstOrNull { it.size > 1 && it[0] == "bolt11" }?.get(1)
|
fun lnInvoice() = tags.firstOrNull { it.size > 1 && it[0] == "bolt11" }?.get(1)
|
||||||
|
|||||||
Reference in New Issue
Block a user