mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-19 08:09:12 +01:00
Fix DB write connection starvation in InAppPaymentsBottomSheetDelegate.
This commit is contained in:
@@ -236,36 +236,35 @@ class InAppPaymentTable(context: Context, databaseHelper: SignalDatabase) : Data
|
||||
* Retrieves all InAppPayment objects for donations that have been marked NOTIFIED = 0, and then marks them
|
||||
* all as notified.
|
||||
*/
|
||||
fun consumeDonationPaymentsToNotifyUser(): List<InAppPayment> {
|
||||
return writableDatabase.withinTransaction { db ->
|
||||
val payments = db.select()
|
||||
.from(TABLE_NAME)
|
||||
.where("$NOTIFIED = ? AND $TYPE != ?", 0, InAppPaymentType.serialize(InAppPaymentType.RECURRING_BACKUP))
|
||||
.run()
|
||||
.readToList(mapper = { InAppPayment.deserialize(it) })
|
||||
|
||||
db.update(TABLE_NAME).values(NOTIFIED to 1)
|
||||
.where("$TYPE != ?", InAppPaymentType.serialize(InAppPaymentType.RECURRING_BACKUP))
|
||||
.run()
|
||||
|
||||
payments
|
||||
}
|
||||
}
|
||||
fun consumeDonationPaymentsToNotifyUser(): List<InAppPayment> = consumePaymentsToNotifyUser(
|
||||
where = "$NOTIFIED = ? AND $TYPE != ?",
|
||||
args = arrayOf(0, InAppPaymentType.serialize(InAppPaymentType.RECURRING_BACKUP))
|
||||
)
|
||||
|
||||
/**
|
||||
* Retrieves all InAppPayment objects for backups that have been marked NOTIFIED = 0, and then marks them
|
||||
* all as notified.
|
||||
*/
|
||||
fun consumeBackupPaymentsToNotifyUser(): List<InAppPayment> {
|
||||
fun consumeBackupPaymentsToNotifyUser(): List<InAppPayment> = consumePaymentsToNotifyUser(
|
||||
where = "$NOTIFIED = ? AND $TYPE = ?",
|
||||
args = arrayOf(0, InAppPaymentType.serialize(InAppPaymentType.RECURRING_BACKUP))
|
||||
)
|
||||
|
||||
private fun consumePaymentsToNotifyUser(where: String, args: Array<Any>): List<InAppPayment> {
|
||||
val hasUnnotified = readableDatabase.exists(TABLE_NAME)
|
||||
.where(where, *args)
|
||||
.run()
|
||||
if (!hasUnnotified) return emptyList()
|
||||
|
||||
return writableDatabase.withinTransaction { db ->
|
||||
val payments = db.select()
|
||||
.from(TABLE_NAME)
|
||||
.where("$NOTIFIED = ? AND $TYPE = ?", 0, InAppPaymentType.serialize(InAppPaymentType.RECURRING_BACKUP))
|
||||
.where(where, *args)
|
||||
.run()
|
||||
.readToList(mapper = { InAppPayment.deserialize(it) })
|
||||
|
||||
db.update(TABLE_NAME).values(NOTIFIED to 1)
|
||||
.where("$TYPE = ?", InAppPaymentType.serialize(InAppPaymentType.RECURRING_BACKUP))
|
||||
.where(where, *args)
|
||||
.run()
|
||||
|
||||
payments
|
||||
|
||||
Reference in New Issue
Block a user