NSCv3: process removed entries

This commit is contained in:
Milos Kozak 2023-03-04 17:41:39 +01:00
parent f651f721e0
commit d8235bab29
20 changed files with 340 additions and 79 deletions

View file

@ -43,7 +43,12 @@ interface StoreDataForDb {
val nsIdDeviceStatuses: MutableList<DeviceStatus>
val nsIdFoods: MutableList<Food>
val deleteTreatment: MutableList<String>
val deleteGlucoseValue: MutableList<String>
fun updateDeletedGlucoseValuesInDb()
fun storeTreatmentsToDb()
fun updateDeletedTreatmentsInDb()
fun storeGlucoseValuesToDb()
fun storeFoodsToDb()
fun scheduleNsIdUpdate()

View file

@ -143,8 +143,8 @@ import kotlin.math.roundToInt
.subscribeOn(Schedulers.io())
//BG READINGS -- including invalid/history records
fun findBgReadingByNSIdSingle(nsId: String): Single<ValueWrapper<GlucoseValue>> =
database.glucoseValueDao.findByNSIdMaybe(nsId).toWrappedSingle()
fun findBgReadingByNSId(nsId: String): GlucoseValue? =
database.glucoseValueDao.findByNSId(nsId)
fun getModifiedBgReadingsDataFromId(lastId: Long): Single<List<GlucoseValue>> =
database.glucoseValueDao.getModifiedFrom(lastId)
@ -186,6 +186,9 @@ import kotlin.math.roundToInt
.subscribeOn(Schedulers.io())
// TEMP TARGETS
fun findTemporaryTargetByNSId(nsId: String): TemporaryTarget? =
database.temporaryTargetDao.findByNSId(nsId)
/*
* returns a Pair of the next entity to sync and the ID of the "update".
* The update id might either be the entry id itself if it is a new entry - or the id
@ -253,6 +256,9 @@ import kotlin.math.roundToInt
// PROFILE SWITCH
fun findProfileSwitchByNSId(nsId: String): ProfileSwitch? =
database.profileSwitchDao.findByNSId(nsId)
fun getNextSyncElementProfileSwitch(id: Long): Maybe<Pair<ProfileSwitch, ProfileSwitch>> =
database.profileSwitchDao.getNextModifiedOrNewAfter(id)
.flatMap { nextIdElement ->
@ -309,6 +315,9 @@ import kotlin.math.roundToInt
database.profileSwitchDao.getLastId()
// EFFECTIVE PROFILE SWITCH
fun findEffectiveProfileSwitchByNSId(nsId: String): EffectiveProfileSwitch? =
database.effectiveProfileSwitchDao.findByNSId(nsId)
/*
* returns a Pair of the next entity to sync and the ID of the "update".
* The update id might either be the entry id itself if it is a new entry - or the id
@ -373,6 +382,9 @@ import kotlin.math.roundToInt
*
* It is a Maybe as there might be no next element.
* */
fun findTherapyEventByNSId(nsId: String): TherapyEvent? =
database.therapyEventDao.findByNSId(nsId)
fun getNextSyncElementTherapyEvent(id: Long): Maybe<Pair<TherapyEvent, TherapyEvent>> =
database.therapyEventDao.getNextModifiedOrNewAfter(id)
.flatMap { nextIdElement ->
@ -431,6 +443,9 @@ import kotlin.math.roundToInt
database.therapyEventDao.getLastId()
// FOOD
fun findFoodByNSId(nsId: String): Food? =
database.foodDao.findByNSId(nsId)
/*
* returns a Pair of the next entity to sync and the ID of the "update".
* The update id might either be the entry id itself if it is a new entry - or the id
@ -465,6 +480,9 @@ import kotlin.math.roundToInt
database.foodDao.getLastId()
// BOLUS
fun findBolusByNSId(nsId: String): Bolus? =
database.bolusDao.findByNSId(nsId)
/*
* returns a Pair of the next entity to sync and the ID of the "update".
* The update id might either be the entry id itself if it is a new entry - or the id
@ -531,6 +549,9 @@ import kotlin.math.roundToInt
database.bolusDao.getLastId()
// CARBS
fun findCarbsByNSId(nsId: String): Carbs? =
database.carbsDao.findByNSId(nsId)
private fun expandCarbs(carbs: Carbs): List<Carbs> =
if (carbs.duration == 0L) {
listOf(carbs)
@ -646,6 +667,9 @@ import kotlin.math.roundToInt
database.carbsDao.getLastId()
// BOLUS CALCULATOR RESULT
fun findBolusCalculatorResultByNSId(nsId: String): BolusCalculatorResult? =
database.bolusCalculatorResultDao.findByNSId(nsId)
/*
* returns a Pair of the next entity to sync and the ID of the "update".
* The update id might either be the entry id itself if it is a new entry - or the id
@ -709,6 +733,9 @@ import kotlin.math.roundToInt
database.deviceStatusDao.getLastId()
// TEMPORARY BASAL
fun findTemporaryBasalByNSId(nsId: String): TemporaryBasal? =
database.temporaryBasalDao.findByNSId(nsId)
/*
* returns a Pair of the next entity to sync and the ID of the "update".
* The update id might either be the entry id itself if it is a new entry - or the id
@ -773,6 +800,9 @@ import kotlin.math.roundToInt
database.temporaryBasalDao.getLastId()
// EXTENDED BOLUS
fun findExtendedBolusByNSId(nsId: String): ExtendedBolus? =
database.extendedBolusDao.findByNSId(nsId)
/*
* returns a Pair of the next entity to sync and the ID of the "update".
* The update id might either be the entry id itself if it is a new entry - or the id
@ -844,6 +874,9 @@ import kotlin.math.roundToInt
}
// OFFLINE EVENT
fun findOfflineEventByNSId(nsId: String): OfflineEvent? =
database.offlineEventDao.findByNSId(nsId)
/*
* returns a Pair of the next entity to sync and the ID of the "update".
* The update id might either be the entry id itself if it is a new entry - or the id

View file

@ -29,7 +29,7 @@ internal interface GlucoseValueDao : TraceableDao<GlucoseValue> {
fun getLastId(): Long?
@Query("SELECT * FROM $TABLE_GLUCOSE_VALUES WHERE nightscoutId = :nsId AND referenceId IS NULL")
fun findByNSIdMaybe(nsId: String): Maybe<GlucoseValue>
fun findByNSId(nsId: String): GlucoseValue?
@Query("SELECT * FROM $TABLE_GLUCOSE_VALUES WHERE timestamp = :timestamp AND sourceSensor = :sourceSensor AND referenceId IS NULL")
fun findByTimestampAndSensor(timestamp: Long, sourceSensor: GlucoseValue.SourceSensor): GlucoseValue?

View file

@ -8,10 +8,11 @@ class InvalidateBolusCalculatorResultTransaction(val id: Long) : Transaction<Inv
val result = TransactionResult()
val bolusCalculatorResult = database.bolusCalculatorResultDao.findById(id)
?: throw IllegalArgumentException("There is no such BolusCalculatorResult with the specified ID.")
if (bolusCalculatorResult.isValid) {
bolusCalculatorResult.isValid = false
database.bolusCalculatorResultDao.updateExistingEntry(bolusCalculatorResult)
result.invalidated.add(bolusCalculatorResult)
}
return result
}

View file

@ -8,9 +8,11 @@ class InvalidateBolusTransaction(val id: Long) : Transaction<InvalidateBolusTran
val result = TransactionResult()
val bolus = database.bolusDao.findById(id)
?: throw IllegalArgumentException("There is no such Bolus with the specified ID.")
if (bolus.isValid) {
bolus.isValid = false
database.bolusDao.updateExistingEntry(bolus)
result.invalidated.add(bolus)
}
return result
}

View file

@ -8,9 +8,11 @@ class InvalidateCarbsTransaction(val id: Long) : Transaction<InvalidateCarbsTran
val result = TransactionResult()
val carbs = database.carbsDao.findById(id)
?: throw IllegalArgumentException("There is no such Carbs with the specified ID.")
if (carbs.isValid) {
carbs.isValid = false
database.carbsDao.updateExistingEntry(carbs)
result.invalidated.add(carbs)
}
return result
}

View file

@ -0,0 +1,23 @@
package info.nightscout.database.impl.transactions
import info.nightscout.database.entities.EffectiveProfileSwitch
class InvalidateEffectiveProfileSwitchTransaction(val id: Long) : Transaction<InvalidateEffectiveProfileSwitchTransaction.TransactionResult>() {
override fun run(): TransactionResult {
val result = TransactionResult()
val effectiveProfileSwitch = database.effectiveProfileSwitchDao.findById(id)
?: throw IllegalArgumentException("There is no such EffectiveProfileSwitch with the specified ID.")
if (effectiveProfileSwitch.isValid) {
effectiveProfileSwitch.isValid = false
database.effectiveProfileSwitchDao.updateExistingEntry(effectiveProfileSwitch)
result.invalidated.add(effectiveProfileSwitch)
}
return result
}
class TransactionResult {
val invalidated = mutableListOf<EffectiveProfileSwitch>()
}
}

View file

@ -8,9 +8,11 @@ class InvalidateExtendedBolusTransaction(val id: Long) : Transaction<InvalidateE
val result = TransactionResult()
val extendedBolus = database.extendedBolusDao.findById(id)
?: throw IllegalArgumentException("There is no such Extended Bolus with the specified ID.")
if (extendedBolus.isValid) {
extendedBolus.isValid = false
database.extendedBolusDao.updateExistingEntry(extendedBolus)
result.invalidated.add(extendedBolus)
}
return result
}

View file

@ -5,7 +5,9 @@ class InvalidateFoodTransaction(val id: Long) : Transaction<Unit>() {
override fun run() {
val food = database.foodDao.findById(id)
?: throw IllegalArgumentException("There is no such Food with the specified ID.")
if (food.isValid) {
food.isValid = false
database.foodDao.updateExistingEntry(food)
}
}
}

View file

@ -11,9 +11,11 @@ class InvalidateGlucoseValueTransaction(val id: Long) : Transaction<InvalidateGl
val result = TransactionResult()
val glucoseValue = database.glucoseValueDao.findById(id)
?: throw IllegalArgumentException("There is no such GlucoseValue with the specified ID.")
if (glucoseValue.isValid) {
glucoseValue.isValid = false
database.glucoseValueDao.updateExistingEntry(glucoseValue)
result.invalidated.add(glucoseValue)
}
return result
}

View file

@ -1,22 +0,0 @@
package info.nightscout.database.impl.transactions
import info.nightscout.database.entities.ProfileSwitch
class InvalidateNsIdProfileSwitchTransaction(val nsId: String) : Transaction<InvalidateNsIdProfileSwitchTransaction.TransactionResult>() {
override fun run() : TransactionResult{
val result = TransactionResult()
val current = database.profileSwitchDao.findByNSId(nsId)
if (current != null) {
current.isValid = false
database.profileSwitchDao.updateExistingEntry(current)
result.invalidated.add(current)
}
return result
}
class TransactionResult {
val invalidated = mutableListOf<ProfileSwitch>()
}
}

View file

@ -1,10 +1,23 @@
package info.nightscout.database.impl.transactions
class InvalidateOfflineEventTransaction(val id: Long) : Transaction<Unit>() {
override fun run() {
import info.nightscout.database.entities.OfflineEvent
class InvalidateOfflineEventTransaction(val id: Long) : Transaction<InvalidateOfflineEventTransaction.TransactionResult>() {
override fun run(): TransactionResult {
val result = TransactionResult()
val offlineEvent = database.offlineEventDao.findById(id)
?: throw IllegalArgumentException("There is no such OfflineEvent with the specified ID.")
if (offlineEvent.isValid) {
offlineEvent.isValid = false
database.offlineEventDao.updateExistingEntry(offlineEvent)
result.invalidated.add(offlineEvent)
}
return result
}
class TransactionResult {
val invalidated = mutableListOf<OfflineEvent>()
}
}

View file

@ -8,9 +8,11 @@ class InvalidateProfileSwitchTransaction(val id: Long) : Transaction<InvalidateP
val result = TransactionResult()
val profileSwitch = database.profileSwitchDao.findById(id)
?: throw IllegalArgumentException("There is no such ProfileSwitch with the specified ID.")
if (profileSwitch.isValid) {
profileSwitch.isValid = false
database.profileSwitchDao.updateExistingEntry(profileSwitch)
result.invalidated.add(profileSwitch)
}
return result
}

View file

@ -8,9 +8,11 @@ class InvalidateTemporaryBasalTransaction(val id: Long) : Transaction<Invalidate
val result = TransactionResult()
val temporaryBasal = database.temporaryBasalDao.findById(id)
?: throw IllegalArgumentException("There is no such Temporary Basal with the specified ID.")
if (temporaryBasal.isValid) {
temporaryBasal.isValid = false
database.temporaryBasalDao.updateExistingEntry(temporaryBasal)
result.invalidated.add(temporaryBasal)
}
return result
}

View file

@ -10,9 +10,11 @@ class InvalidateTemporaryBasalTransactionWithPumpId(val pumpId: Long, val pumpTy
val result = TransactionResult()
val temporaryBasal = database.temporaryBasalDao.findByPumpIds(pumpId, pumpType, pumpSerial)
?: throw IllegalArgumentException("There is no such Temporary Basal with the specified temp ID.")
if (temporaryBasal.isValid) {
temporaryBasal.isValid = false
database.temporaryBasalDao.updateExistingEntry(temporaryBasal)
result.invalidated.add(temporaryBasal)
}
return result
}

View file

@ -8,9 +8,11 @@ class InvalidateTemporaryBasalWithTempIdTransaction(val tempId: Long) : Transact
val result = TransactionResult()
val temporaryBasal = database.temporaryBasalDao.findByTempId(tempId)
?: throw IllegalArgumentException("There is no such Temporary Basal with the specified temp ID.")
if (temporaryBasal.isValid) {
temporaryBasal.isValid = false
database.temporaryBasalDao.updateExistingEntry(temporaryBasal)
result.invalidated.add(temporaryBasal)
}
return result
}

View file

@ -1,10 +1,23 @@
package info.nightscout.database.impl.transactions
class InvalidateTemporaryTargetTransaction(val id: Long) : Transaction<Unit>() {
override fun run() {
import info.nightscout.database.entities.TemporaryTarget
class InvalidateTemporaryTargetTransaction(val id: Long) : Transaction<InvalidateTemporaryTargetTransaction.TransactionResult>() {
override fun run(): TransactionResult {
val result = TransactionResult()
val temporaryTarget = database.temporaryTargetDao.findById(id)
?: throw IllegalArgumentException("There is no such TemporaryTarget with the specified ID.")
if (temporaryTarget.isValid) {
temporaryTarget.isValid = false
database.temporaryTargetDao.updateExistingEntry(temporaryTarget)
result.invalidated.add(temporaryTarget)
}
return result
}
class TransactionResult {
val invalidated = mutableListOf<TemporaryTarget>()
}
}

View file

@ -8,9 +8,11 @@ class InvalidateTherapyEventTransaction(val id: Long) : Transaction<InvalidateTh
val result = TransactionResult()
val therapyEvent = database.therapyEventDao.findById(id)
?: throw IllegalArgumentException("There is no such TherapyEvent with the specified ID.")
if (therapyEvent.isValid) {
therapyEvent.isValid = false
database.therapyEventDao.updateExistingEntry(therapyEvent)
result.invalidated.add(therapyEvent)
}
return result
}

View file

@ -18,6 +18,17 @@ import info.nightscout.database.entities.UserEntry
import info.nightscout.database.entities.ValueWithUnit
import info.nightscout.database.impl.AppRepository
import info.nightscout.database.impl.transactions.CgmSourceTransaction
import info.nightscout.database.impl.transactions.InvalidateBolusCalculatorResultTransaction
import info.nightscout.database.impl.transactions.InvalidateBolusTransaction
import info.nightscout.database.impl.transactions.InvalidateCarbsTransaction
import info.nightscout.database.impl.transactions.InvalidateEffectiveProfileSwitchTransaction
import info.nightscout.database.impl.transactions.InvalidateExtendedBolusTransaction
import info.nightscout.database.impl.transactions.InvalidateGlucoseValueTransaction
import info.nightscout.database.impl.transactions.InvalidateOfflineEventTransaction
import info.nightscout.database.impl.transactions.InvalidateProfileSwitchTransaction
import info.nightscout.database.impl.transactions.InvalidateTemporaryBasalTransaction
import info.nightscout.database.impl.transactions.InvalidateTemporaryTargetTransaction
import info.nightscout.database.impl.transactions.InvalidateTherapyEventTransaction
import info.nightscout.database.impl.transactions.SyncNsBolusCalculatorResultTransaction
import info.nightscout.database.impl.transactions.SyncNsBolusTransaction
import info.nightscout.database.impl.transactions.SyncNsCarbsTransaction
@ -51,6 +62,7 @@ import info.nightscout.interfaces.nsclient.StoreDataForDb
import info.nightscout.interfaces.pump.VirtualPump
import info.nightscout.interfaces.source.NSClientSource
import info.nightscout.interfaces.ui.UiInteraction
import info.nightscout.plugins.sync.R
import info.nightscout.rx.bus.RxBus
import info.nightscout.rx.events.EventNSClientNewLog
import info.nightscout.rx.logging.AAPSLogger
@ -104,6 +116,8 @@ class StoreDataForDbImpl @Inject constructor(
override val nsIdDeviceStatuses: MutableList<DeviceStatus> = mutableListOf()
override val nsIdFoods: MutableList<Food> = mutableListOf()
override val deleteTreatment: MutableList<String> = mutableListOf()
override val deleteGlucoseValue: MutableList<String> = mutableListOf()
private val userEntries: MutableList<UserEntry> = mutableListOf()
private val inserted = HashMap<String, Long>()
@ -961,6 +975,157 @@ class StoreDataForDbImpl @Inject constructor(
rxBus.send(EventNSClientNewLog("● DONE NSIDs", ""))
}
override fun updateDeletedTreatmentsInDb() {
deleteTreatment.forEach { id ->
if (sp.getBoolean(info.nightscout.core.utils.R.string.key_ns_receive_insulin, false) || config.NSCLIENT)
repository.findBolusByNSId(id)?.let { bolus ->
repository.runTransactionForResult(InvalidateBolusTransaction(bolus.id))
.doOnError { aapsLogger.error(LTag.DATABASE, "Error while invalidating Bolus", it) }
.blockingGet()
.also { result ->
result.invalidated.forEach {
aapsLogger.debug(LTag.DATABASE, "Invalidated Bolus $it")
invalidated.inc(Bolus::class.java.simpleName)
}
}
}
if (sp.getBoolean(info.nightscout.core.utils.R.string.key_ns_receive_carbs, false) || config.NSCLIENT)
repository.findCarbsByNSId(id)?.let { carb ->
repository.runTransactionForResult(InvalidateCarbsTransaction(carb.id))
.doOnError { aapsLogger.error(LTag.DATABASE, "Error while invalidating Carbs", it) }
.blockingGet()
.also { result ->
result.invalidated.forEach {
aapsLogger.debug(LTag.DATABASE, "Invalidated Carbs $it")
invalidated.inc(Carbs::class.java.simpleName)
}
}
}
if (sp.getBoolean(info.nightscout.core.utils.R.string.key_ns_receive_temp_target, false) || config.NSCLIENT)
repository.findTemporaryTargetByNSId(id)?.let { gv ->
repository.runTransactionForResult(InvalidateTemporaryTargetTransaction(gv.id))
.doOnError { aapsLogger.error(LTag.DATABASE, "Error while invalidating TemporaryTarget", it) }
.blockingGet()
.also { result ->
result.invalidated.forEach {
aapsLogger.debug(LTag.DATABASE, "Invalidated TemporaryTarget $it")
invalidated.inc(TemporaryTarget::class.java.simpleName)
}
}
}
if (config.isEngineeringMode() && sp.getBoolean(R.string.key_ns_receive_tbr_eb, false) || config.NSCLIENT)
repository.findTemporaryBasalByNSId(id)?.let { gv ->
repository.runTransactionForResult(InvalidateTemporaryBasalTransaction(gv.id))
.doOnError { aapsLogger.error(LTag.DATABASE, "Error while invalidating TemporaryBasal", it) }
.blockingGet()
.also { result ->
result.invalidated.forEach {
aapsLogger.debug(LTag.DATABASE, "Invalidated TemporaryBasal $it")
invalidated.inc(TemporaryBasal::class.java.simpleName)
}
}
}
if (sp.getBoolean(info.nightscout.core.utils.R.string.key_ns_receive_profile_switch, false) || config.NSCLIENT)
repository.findEffectiveProfileSwitchByNSId(id)?.let { gv ->
repository.runTransactionForResult(InvalidateEffectiveProfileSwitchTransaction(gv.id))
.doOnError { aapsLogger.error(LTag.DATABASE, "Error while invalidating EffectiveProfileSwitch", it) }
.blockingGet()
.also { result ->
result.invalidated.forEach {
aapsLogger.debug(LTag.DATABASE, "Invalidated EffectiveProfileSwitch $it")
invalidated.inc(EffectiveProfileSwitch::class.java.simpleName)
}
}
}
if (sp.getBoolean(info.nightscout.core.utils.R.string.key_ns_receive_profile_switch, false) || config.NSCLIENT)
repository.findProfileSwitchByNSId(id)?.let { gv ->
repository.runTransactionForResult(InvalidateProfileSwitchTransaction(gv.id))
.doOnError { aapsLogger.error(LTag.DATABASE, "Error while invalidating ProfileSwitch", it) }
.blockingGet()
.also { result ->
result.invalidated.forEach {
aapsLogger.debug(LTag.DATABASE, "Invalidated ProfileSwitch $it")
invalidated.inc(ProfileSwitch::class.java.simpleName)
}
}
}
repository.findBolusCalculatorResultByNSId(id)?.let { gv ->
repository.runTransactionForResult(InvalidateBolusCalculatorResultTransaction(gv.id))
.doOnError { aapsLogger.error(LTag.DATABASE, "Error while invalidating BolusCalculatorResult", it) }
.blockingGet()
.also { result ->
result.invalidated.forEach {
aapsLogger.debug(LTag.DATABASE, "Invalidated BolusCalculatorResult $it")
invalidated.inc(BolusCalculatorResult::class.java.simpleName)
}
}
}
if (sp.getBoolean(info.nightscout.core.utils.R.string.key_ns_receive_therapy_events, false) || config.NSCLIENT)
repository.findTherapyEventByNSId(id)?.let { gv ->
repository.runTransactionForResult(InvalidateTherapyEventTransaction(gv.id))
.doOnError { aapsLogger.error(LTag.DATABASE, "Error while invalidating TherapyEvent", it) }
.blockingGet()
.also { result ->
result.invalidated.forEach {
aapsLogger.debug(LTag.DATABASE, "Invalidated TherapyEvent $it")
invalidated.inc(TherapyEvent::class.java.simpleName)
}
}
}
if (sp.getBoolean(info.nightscout.core.utils.R.string.key_ns_receive_offline_event, false) && config.isEngineeringMode() || config.NSCLIENT)
repository.findOfflineEventByNSId(id)?.let { gv ->
repository.runTransactionForResult(InvalidateOfflineEventTransaction(gv.id))
.doOnError { aapsLogger.error(LTag.DATABASE, "Error while invalidating OfflineEvent", it) }
.blockingGet()
.also { result ->
result.invalidated.forEach {
aapsLogger.debug(LTag.DATABASE, "Invalidated OfflineEvent $it")
invalidated.inc(OfflineEvent::class.java.simpleName)
}
}
}
if (config.isEngineeringMode() && sp.getBoolean(R.string.key_ns_receive_tbr_eb, false) || config.NSCLIENT)
repository.findExtendedBolusByNSId(id)?.let { gv ->
repository.runTransactionForResult(InvalidateExtendedBolusTransaction(gv.id))
.doOnError { aapsLogger.error(LTag.DATABASE, "Error while invalidating ExtendedBolus", it) }
.blockingGet()
.also { result ->
result.invalidated.forEach {
aapsLogger.debug(LTag.DATABASE, "Invalidated ExtendedBolus $it")
invalidated.inc(ExtendedBolus::class.java.simpleName)
}
}
}
}
sendLog("Bolus", Bolus::class.java.simpleName)
sendLog("Carbs", Carbs::class.java.simpleName)
sendLog("TemporaryTarget", TemporaryTarget::class.java.simpleName)
sendLog("TemporaryBasal", TemporaryBasal::class.java.simpleName)
sendLog("EffectiveProfileSwitch", EffectiveProfileSwitch::class.java.simpleName)
sendLog("ProfileSwitch", ProfileSwitch::class.java.simpleName)
sendLog("BolusCalculatorResult", BolusCalculatorResult::class.java.simpleName)
sendLog("TherapyEvent", TherapyEvent::class.java.simpleName)
sendLog("OfflineEvent", OfflineEvent::class.java.simpleName)
sendLog("ExtendedBolus", ExtendedBolus::class.java.simpleName)
}
override fun updateDeletedGlucoseValuesInDb() {
deleteGlucoseValue.forEach { id ->
repository.findBgReadingByNSId(id)?.let { gv ->
repository.runTransactionForResult(InvalidateGlucoseValueTransaction(gv.id))
.doOnError { aapsLogger.error(LTag.DATABASE, "Error while invalidating GlucoseValue", it) }
.blockingGet()
.also { result ->
result.invalidated.forEach {
aapsLogger.debug(LTag.DATABASE, "Invalidated GlucoseValue $it")
invalidated.inc(GlucoseValue::class.java.simpleName)
}
}
}
}
sendLog("GlucoseValue", GlucoseValue::class.java.simpleName)
}
private fun sendLog(item: String, clazz: String) {
inserted[clazz]?.let {
rxBus.send(EventNSClientNewLog("◄ INSERT", "$item $it"))

View file

@ -461,7 +461,17 @@ class NSClientV3Plugin @Inject constructor(
private val onDataDelete = Emitter.Listener { args ->
val response = args[0] as JSONObject
aapsLogger.debug(LTag.NSCLIENT, "onDataDelete: $response")
rxBus.send(EventNSClientNewLog("◄ WS DELETE", "${response.optString("collection")} ${response.optString("doc")}"))
val collection = response.optString("colName") ?: return@Listener
val identifier = response.optString("identifier") ?: return@Listener
rxBus.send(EventNSClientNewLog("◄ WS DELETE", "$collection $identifier"))
if (collection == "treatments") {
storeDataForDb.deleteTreatment.add(identifier)
storeDataForDb.updateDeletedTreatmentsInDb()
}
if (collection == "entries") {
storeDataForDb.deleteGlucoseValue.add(identifier)
storeDataForDb.updateDeletedGlucoseValuesInDb()
}
}
private val onAnnouncement = Emitter.Listener { args ->