NSClient sync improvement

This commit is contained in:
Milos Kozak 2021-05-14 08:54:11 +02:00
parent 6c851b5e7b
commit 1af0cc5aeb
16 changed files with 219 additions and 44 deletions

View file

@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.general.nsclient
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.AppRepository
import info.nightscout.androidaps.database.ValueWrapper
import info.nightscout.androidaps.database.entities.* import info.nightscout.androidaps.database.entities.*
import info.nightscout.androidaps.extensions.toJson import info.nightscout.androidaps.extensions.toJson
import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.interfaces.ActivePlugin
@ -78,7 +79,13 @@ class DataSyncSelectorImplementation @Inject constructor(
private var lastBolusId = -1L private var lastBolusId = -1L
private var lastBolusTime = -1L private var lastBolusTime = -1L
override fun processChangedBolusesCompat(): Boolean { override fun processChangedBolusesCompat(): Boolean {
val startId = sp.getLong(R.string.key_ns_bolus_last_synced_id, 0) val lastDbIdWrapped = appRepository.getLastBolusIdWrapped().blockingGet()
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
var startId = sp.getLong(R.string.key_ns_bolus_last_synced_id, 0)
if (startId > lastDbId) {
sp.putLong(R.string.key_ns_bolus_last_synced_id, 0)
startId = 0
}
if (startId == lastBolusId && dateUtil.now() - lastBolusTime < 5000) return false if (startId == lastBolusId && dateUtil.now() - lastBolusTime < 5000) return false
lastBolusId = startId lastBolusId = startId
lastBolusTime = dateUtil.now() lastBolusTime = dateUtil.now()
@ -87,10 +94,10 @@ class DataSyncSelectorImplementation @Inject constructor(
when { when {
// without nsId = create new // without nsId = create new
bolus.first.interfaceIDs.nightscoutId == null -> bolus.first.interfaceIDs.nightscoutId == null ->
nsClientPlugin.nsClientService?.dbAdd("treatments", bolus.first.toJson(dateUtil), DataSyncSelector.PairBolus(bolus.first, bolus.second)) nsClientPlugin.nsClientService?.dbAdd("treatments", bolus.first.toJson(dateUtil), DataSyncSelector.PairBolus(bolus.first, bolus.second), "$startId/$lastDbId")
// with nsId = update // with nsId = update
bolus.first.interfaceIDs.nightscoutId != null -> bolus.first.interfaceIDs.nightscoutId != null ->
nsClientPlugin.nsClientService?.dbUpdate("treatments", bolus.first.interfaceIDs.nightscoutId, bolus.first.toJson(dateUtil), DataSyncSelector.PairBolus(bolus.first, bolus.second)) nsClientPlugin.nsClientService?.dbUpdate("treatments", bolus.first.interfaceIDs.nightscoutId, bolus.first.toJson(dateUtil), DataSyncSelector.PairBolus(bolus.first, bolus.second), "$startId/$lastDbId")
} }
return true return true
} }
@ -115,7 +122,13 @@ class DataSyncSelectorImplementation @Inject constructor(
private var lastCarbsId = -1L private var lastCarbsId = -1L
private var lastCarbsTime = -1L private var lastCarbsTime = -1L
override fun processChangedCarbsCompat(): Boolean { override fun processChangedCarbsCompat(): Boolean {
val startId = sp.getLong(R.string.key_ns_carbs_last_synced_id, 0) val lastDbIdWrapped = appRepository.getLastCarbsIdWrapped().blockingGet()
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
var startId = sp.getLong(R.string.key_ns_carbs_last_synced_id, 0)
if (startId > lastDbId) {
sp.putLong(R.string.key_ns_carbs_last_synced_id, 0)
startId = 0
}
if (startId == lastCarbsId && dateUtil.now() - lastCarbsTime < 5000) return false if (startId == lastCarbsId && dateUtil.now() - lastCarbsTime < 5000) return false
lastCarbsId = startId lastCarbsId = startId
lastCarbsTime = dateUtil.now() lastCarbsTime = dateUtil.now()
@ -124,10 +137,10 @@ class DataSyncSelectorImplementation @Inject constructor(
when { when {
// without nsId = create new // without nsId = create new
carb.first.interfaceIDs.nightscoutId == null -> carb.first.interfaceIDs.nightscoutId == null ->
nsClientPlugin.nsClientService?.dbAdd("treatments", carb.first.toJson(dateUtil), DataSyncSelector.PairCarbs(carb.first, carb.second)) nsClientPlugin.nsClientService?.dbAdd("treatments", carb.first.toJson(dateUtil), DataSyncSelector.PairCarbs(carb.first, carb.second), "$startId/$lastDbId")
// with nsId = update // with nsId = update
carb.first.interfaceIDs.nightscoutId != null -> carb.first.interfaceIDs.nightscoutId != null ->
nsClientPlugin.nsClientService?.dbUpdate("treatments", carb.first.interfaceIDs.nightscoutId, carb.first.toJson(dateUtil), DataSyncSelector.PairCarbs(carb.first, carb.second)) nsClientPlugin.nsClientService?.dbUpdate("treatments", carb.first.interfaceIDs.nightscoutId, carb.first.toJson(dateUtil), DataSyncSelector.PairCarbs(carb.first, carb.second), "$startId/$lastDbId")
} }
return true return true
} }
@ -152,7 +165,13 @@ class DataSyncSelectorImplementation @Inject constructor(
private var lastBcrId = -1L private var lastBcrId = -1L
private var lastBcrTime = -1L private var lastBcrTime = -1L
override fun processChangedBolusCalculatorResultsCompat(): Boolean { override fun processChangedBolusCalculatorResultsCompat(): Boolean {
val startId = sp.getLong(R.string.key_ns_bolus_calculator_result_last_synced_id, 0) val lastDbIdWrapped = appRepository.getLastBolusCalculatorResultIdWrapped().blockingGet()
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
var startId = sp.getLong(R.string.key_ns_bolus_calculator_result_last_synced_id, 0)
if (startId > lastDbId) {
sp.putLong(R.string.key_ns_bolus_calculator_result_last_synced_id, 0)
startId = 0
}
if (startId == lastBcrId && dateUtil.now() - lastBcrTime < 5000) return false if (startId == lastBcrId && dateUtil.now() - lastBcrTime < 5000) return false
lastBcrId = startId lastBcrId = startId
lastBcrTime = dateUtil.now() lastBcrTime = dateUtil.now()
@ -161,10 +180,10 @@ class DataSyncSelectorImplementation @Inject constructor(
when { when {
// without nsId = create new // without nsId = create new
bolusCalculatorResult.first.interfaceIDs.nightscoutId == null -> bolusCalculatorResult.first.interfaceIDs.nightscoutId == null ->
nsClientPlugin.nsClientService?.dbAdd("treatments", bolusCalculatorResult.first.toJson(dateUtil), DataSyncSelector.PairBolusCalculatorResult(bolusCalculatorResult.first, bolusCalculatorResult.second)) nsClientPlugin.nsClientService?.dbAdd("treatments", bolusCalculatorResult.first.toJson(dateUtil), DataSyncSelector.PairBolusCalculatorResult(bolusCalculatorResult.first, bolusCalculatorResult.second), "$startId/$lastDbId")
// with nsId = update // with nsId = update
bolusCalculatorResult.first.interfaceIDs.nightscoutId != null -> bolusCalculatorResult.first.interfaceIDs.nightscoutId != null ->
nsClientPlugin.nsClientService?.dbUpdate("treatments", bolusCalculatorResult.first.interfaceIDs.nightscoutId, bolusCalculatorResult.first.toJson(dateUtil), DataSyncSelector.PairBolusCalculatorResult(bolusCalculatorResult.first, bolusCalculatorResult.second)) nsClientPlugin.nsClientService?.dbUpdate("treatments", bolusCalculatorResult.first.interfaceIDs.nightscoutId, bolusCalculatorResult.first.toJson(dateUtil), DataSyncSelector.PairBolusCalculatorResult(bolusCalculatorResult.first, bolusCalculatorResult.second), "$startId/$lastDbId")
} }
return true return true
} }
@ -189,7 +208,13 @@ class DataSyncSelectorImplementation @Inject constructor(
private var lastTtId = -1L private var lastTtId = -1L
private var lastTtTime = -1L private var lastTtTime = -1L
override fun processChangedTempTargetsCompat(): Boolean { override fun processChangedTempTargetsCompat(): Boolean {
val startId = sp.getLong(R.string.key_ns_temporary_target_last_synced_id, 0) val lastDbIdWrapped = appRepository.getLastTempTargetIdWrapped().blockingGet()
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
var startId = sp.getLong(R.string.key_ns_temporary_target_last_synced_id, 0)
if (startId > lastDbId) {
sp.putLong(R.string.key_ns_temporary_target_last_synced_id, 0)
startId = 0
}
if (startId == lastTtId && dateUtil.now() - lastTtTime < 5000) return false if (startId == lastTtId && dateUtil.now() - lastTtTime < 5000) return false
lastTtId = startId lastTtId = startId
lastTtTime = dateUtil.now() lastTtTime = dateUtil.now()
@ -198,10 +223,10 @@ class DataSyncSelectorImplementation @Inject constructor(
when { when {
// without nsId = create new // without nsId = create new
tt.first.interfaceIDs.nightscoutId == null -> tt.first.interfaceIDs.nightscoutId == null ->
nsClientPlugin.nsClientService?.dbAdd("treatments", tt.first.toJson(profileFunction.getUnits(), dateUtil), DataSyncSelector.PairTemporaryTarget(tt.first, tt.second)) nsClientPlugin.nsClientService?.dbAdd("treatments", tt.first.toJson(profileFunction.getUnits(), dateUtil), DataSyncSelector.PairTemporaryTarget(tt.first, tt.second), "$startId/$lastDbId")
// existing with nsId = update // existing with nsId = update
tt.first.interfaceIDs.nightscoutId != null -> tt.first.interfaceIDs.nightscoutId != null ->
nsClientPlugin.nsClientService?.dbUpdate("treatments", tt.first.interfaceIDs.nightscoutId, tt.first.toJson(profileFunction.getUnits(), dateUtil), DataSyncSelector.PairTemporaryTarget(tt.first, tt.second)) nsClientPlugin.nsClientService?.dbUpdate("treatments", tt.first.interfaceIDs.nightscoutId, tt.first.toJson(profileFunction.getUnits(), dateUtil), DataSyncSelector.PairTemporaryTarget(tt.first, tt.second), "$startId/$lastDbId")
} }
return true return true
} }
@ -226,7 +251,13 @@ class DataSyncSelectorImplementation @Inject constructor(
private var lastFoodId = -1L private var lastFoodId = -1L
private var lastFoodTime = -1L private var lastFoodTime = -1L
override fun processChangedFoodsCompat(): Boolean { override fun processChangedFoodsCompat(): Boolean {
val startId = sp.getLong(R.string.key_ns_food_last_synced_id, 0) val lastDbIdWrapped = appRepository.getLastFoodIdWrapped().blockingGet()
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
var startId = sp.getLong(R.string.key_ns_food_last_synced_id, 0)
if (startId > lastDbId) {
sp.putLong(R.string.key_ns_food_last_synced_id, 0)
startId = 0
}
if (startId == lastFoodId && dateUtil.now() - lastFoodTime < 5000) return false if (startId == lastFoodId && dateUtil.now() - lastFoodTime < 5000) return false
lastFoodId = startId lastFoodId = startId
lastFoodTime = dateUtil.now() lastFoodTime = dateUtil.now()
@ -235,10 +266,10 @@ class DataSyncSelectorImplementation @Inject constructor(
when { when {
// without nsId = create new // without nsId = create new
food.first.interfaceIDs.nightscoutId == null -> food.first.interfaceIDs.nightscoutId == null ->
nsClientPlugin.nsClientService?.dbAdd("food", food.first.toJson(), DataSyncSelector.PairFood(food.first, food.second)) nsClientPlugin.nsClientService?.dbAdd("food", food.first.toJson(), DataSyncSelector.PairFood(food.first, food.second), "$startId/$lastDbId")
// with nsId = update // with nsId = update
food.first.interfaceIDs.nightscoutId != null -> food.first.interfaceIDs.nightscoutId != null ->
nsClientPlugin.nsClientService?.dbUpdate("food", food.first.interfaceIDs.nightscoutId, food.first.toJson(), DataSyncSelector.PairFood(food.first, food.second)) nsClientPlugin.nsClientService?.dbUpdate("food", food.first.interfaceIDs.nightscoutId, food.first.toJson(), DataSyncSelector.PairFood(food.first, food.second), "$startId/$lastDbId")
} }
return true return true
} }
@ -263,7 +294,13 @@ class DataSyncSelectorImplementation @Inject constructor(
private var lastGvId = -1L private var lastGvId = -1L
private var lastGvTime = -1L private var lastGvTime = -1L
override fun processChangedGlucoseValuesCompat(): Boolean { override fun processChangedGlucoseValuesCompat(): Boolean {
val startId = sp.getLong(R.string.key_ns_glucose_value_last_synced_id, 0) val lastDbIdWrapped = appRepository.getLastGlucoseValueIdWrapped().blockingGet()
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
var startId = sp.getLong(R.string.key_ns_glucose_value_last_synced_id, 0)
if (startId > lastDbId) {
sp.putLong(R.string.key_ns_glucose_value_last_synced_id, 0)
startId = 0
}
if (startId == lastGvId && dateUtil.now() - lastGvTime < 5000) return false if (startId == lastGvId && dateUtil.now() - lastGvTime < 5000) return false
lastGvId = startId lastGvId = startId
lastGvTime = dateUtil.now() lastGvTime = dateUtil.now()
@ -273,13 +310,17 @@ class DataSyncSelectorImplementation @Inject constructor(
when { when {
// without nsId = create new // without nsId = create new
gv.first.interfaceIDs.nightscoutId == null -> gv.first.interfaceIDs.nightscoutId == null ->
nsClientPlugin.nsClientService?.dbAdd("entries", gv.first.toJson(dateUtil), DataSyncSelector.PairGlucoseValue(gv.first, gv.second)) nsClientPlugin.nsClientService?.dbAdd("entries", gv.first.toJson(dateUtil), DataSyncSelector.PairGlucoseValue(gv.first, gv.second), "$startId/$lastDbId")
// with nsId = update // with nsId = update
gv.first.interfaceIDs.nightscoutId != null -> gv.first.interfaceIDs.nightscoutId != null ->
nsClientPlugin.nsClientService?.dbUpdate("entries", gv.first.interfaceIDs.nightscoutId, gv.first.toJson(dateUtil), DataSyncSelector.PairGlucoseValue(gv.first, gv.second)) nsClientPlugin.nsClientService?.dbUpdate("entries", gv.first.interfaceIDs.nightscoutId, gv.first.toJson(dateUtil), DataSyncSelector.PairGlucoseValue(gv.first, gv.second), "$startId/$lastDbId")
} }
return true return true
} else confirmLastGlucoseValueIdIfGreater(gv.second) } else {
confirmLastGlucoseValueIdIfGreater(gv.second)
lastGvId = -1
processChangedGlucoseValuesCompat()
}
} }
return false return false
} }
@ -302,7 +343,13 @@ class DataSyncSelectorImplementation @Inject constructor(
private var lastTeId = -1L private var lastTeId = -1L
private var lastTeTime = -1L private var lastTeTime = -1L
override fun processChangedTherapyEventsCompat(): Boolean { override fun processChangedTherapyEventsCompat(): Boolean {
val startId = sp.getLong(R.string.key_ns_therapy_event_last_synced_id, 0) val lastDbIdWrapped = appRepository.getLastTherapyEventIdWrapped().blockingGet()
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
var startId = sp.getLong(R.string.key_ns_therapy_event_last_synced_id, 0)
if (startId > lastDbId) {
sp.putLong(R.string.key_ns_therapy_event_last_synced_id, 0)
startId = 0
}
if (startId == lastTeId && dateUtil.now() - lastTeTime < 5000) return false if (startId == lastTeId && dateUtil.now() - lastTeTime < 5000) return false
lastTeId = startId lastTeId = startId
lastTeTime = dateUtil.now() lastTeTime = dateUtil.now()
@ -311,10 +358,10 @@ class DataSyncSelectorImplementation @Inject constructor(
when { when {
// without nsId = create new // without nsId = create new
te.first.interfaceIDs.nightscoutId == null -> te.first.interfaceIDs.nightscoutId == null ->
nsClientPlugin.nsClientService?.dbAdd("treatments", te.first.toJson(), DataSyncSelector.PairTherapyEvent(te.first, te.second)) nsClientPlugin.nsClientService?.dbAdd("treatments", te.first.toJson(), DataSyncSelector.PairTherapyEvent(te.first, te.second), "$startId/$lastDbId")
// nsId = update // nsId = update
te.first.interfaceIDs.nightscoutId != null -> te.first.interfaceIDs.nightscoutId != null ->
nsClientPlugin.nsClientService?.dbUpdate("treatments", te.first.interfaceIDs.nightscoutId, te.first.toJson(), DataSyncSelector.PairTherapyEvent(te.first, te.second)) nsClientPlugin.nsClientService?.dbUpdate("treatments", te.first.interfaceIDs.nightscoutId, te.first.toJson(), DataSyncSelector.PairTherapyEvent(te.first, te.second), "$startId/$lastDbId")
} }
return true return true
} }
@ -338,7 +385,13 @@ class DataSyncSelectorImplementation @Inject constructor(
private var lastDsId = -1L private var lastDsId = -1L
private var lastDsTime = -1L private var lastDsTime = -1L
override fun processChangedDeviceStatusesCompat(): Boolean { override fun processChangedDeviceStatusesCompat(): Boolean {
val startId = sp.getLong(R.string.key_ns_device_status_last_synced_id, 0) val lastDbIdWrapped = appRepository.getLastDeviceStatusIdWrapped().blockingGet()
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
var startId = sp.getLong(R.string.key_ns_device_status_last_synced_id, 0)
if (startId > lastDbId) {
sp.putLong(R.string.key_ns_device_status_last_synced_id, 0)
startId = 0
}
if (startId == lastDsId && dateUtil.now() - lastDsTime < 5000) return false if (startId == lastDsId && dateUtil.now() - lastDsTime < 5000) return false
lastDsId = startId lastDsId = startId
lastDsTime = dateUtil.now() lastDsTime = dateUtil.now()
@ -347,7 +400,7 @@ class DataSyncSelectorImplementation @Inject constructor(
when { when {
// without nsId = create new // without nsId = create new
deviceStatus.interfaceIDs.nightscoutId == null -> deviceStatus.interfaceIDs.nightscoutId == null ->
nsClientPlugin.nsClientService?.dbAdd("devicestatus", deviceStatus.toJson(dateUtil), deviceStatus) nsClientPlugin.nsClientService?.dbAdd("devicestatus", deviceStatus.toJson(dateUtil), deviceStatus, "$startId/$lastDbId")
// with nsId = ignore // with nsId = ignore
deviceStatus.interfaceIDs.nightscoutId != null -> Any() deviceStatus.interfaceIDs.nightscoutId != null -> Any()
} }
@ -375,23 +428,34 @@ class DataSyncSelectorImplementation @Inject constructor(
private var lastTbrTime = -1L private var lastTbrTime = -1L
override fun processChangedTemporaryBasalsCompat(): Boolean { override fun processChangedTemporaryBasalsCompat(): Boolean {
val useAbsolute = sp.getBoolean(R.string.key_ns_sync_use_absolute, false) val useAbsolute = sp.getBoolean(R.string.key_ns_sync_use_absolute, false)
val startId = sp.getLong(R.string.key_ns_temporary_basal_last_synced_id, 0) val lastDbIdWrapped = appRepository.getLastTemporaryBasalIdWrapped().blockingGet()
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
var startId = sp.getLong(R.string.key_ns_temporary_basal_last_synced_id, 0)
if (startId > lastDbId) {
sp.putLong(R.string.key_ns_temporary_basal_last_synced_id, 0)
startId = 0
}
if (startId == lastTbrId && dateUtil.now() - lastTbrTime < 5000) return false if (startId == lastTbrId && dateUtil.now() - lastTbrTime < 5000) return false
lastTbrId = startId lastTbrId = startId
lastTbrTime = dateUtil.now() lastTbrTime = dateUtil.now()
appRepository.getNextSyncElementTemporaryBasal(startId).blockingGet()?.let { tb -> appRepository.getNextSyncElementTemporaryBasal(startId).blockingGet()?.let { tb ->
aapsLogger.info(LTag.DATABASE, "Loading TemporaryBasal data Start: $startId ID: ${tb.first.id} HistoryID: ${tb.second} ") aapsLogger.info(LTag.DATABASE, "Loading TemporaryBasal data Start: $startId ID: ${tb.first.id} HistoryID: ${tb.second} ")
profileFunction.getProfile(tb.first.timestamp)?.let { profile -> val profile = profileFunction.getProfile(tb.first.timestamp)
if (profile != null) {
when { when {
// without nsId = create new // without nsId = create new
tb.first.interfaceIDs.nightscoutId == null -> tb.first.interfaceIDs.nightscoutId == null ->
nsClientPlugin.nsClientService?.dbAdd("treatments", tb.first.toJson(profile, dateUtil, useAbsolute), DataSyncSelector.PairTemporaryBasal(tb.first, tb.second)) nsClientPlugin.nsClientService?.dbAdd("treatments", tb.first.toJson(profile, dateUtil, useAbsolute), DataSyncSelector.PairTemporaryBasal(tb.first, tb.second), "$startId/$lastDbId")
// with nsId = update // with nsId = update
tb.first.interfaceIDs.nightscoutId != null -> tb.first.interfaceIDs.nightscoutId != null ->
nsClientPlugin.nsClientService?.dbUpdate("treatments", tb.first.interfaceIDs.nightscoutId, tb.first.toJson(profile, dateUtil, useAbsolute), DataSyncSelector.PairTemporaryBasal(tb.first, tb.second)) nsClientPlugin.nsClientService?.dbUpdate("treatments", tb.first.interfaceIDs.nightscoutId, tb.first.toJson(profile, dateUtil, useAbsolute), DataSyncSelector.PairTemporaryBasal(tb.first, tb.second), "$startId/$lastDbId")
} }
return true return true
} ?: confirmLastTemporaryBasalIdIfGreater(tb.second) } else {
confirmLastTemporaryBasalIdIfGreater(tb.second)
lastTbrId = -1
processChangedTemporaryBasalsCompat()
}
} }
return false return false
} }
@ -415,23 +479,34 @@ class DataSyncSelectorImplementation @Inject constructor(
private var lastEbTime = -1L private var lastEbTime = -1L
override fun processChangedExtendedBolusesCompat(): Boolean { override fun processChangedExtendedBolusesCompat(): Boolean {
val useAbsolute = sp.getBoolean(R.string.key_ns_sync_use_absolute, false) val useAbsolute = sp.getBoolean(R.string.key_ns_sync_use_absolute, false)
val startId = sp.getLong(R.string.key_ns_extended_bolus_last_synced_id, 0) val lastDbIdWrapped = appRepository.getLastExtendedBolusIdWrapped().blockingGet()
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
var startId = sp.getLong(R.string.key_ns_extended_bolus_last_synced_id, 0)
if (startId > lastDbId) {
sp.putLong(R.string.key_ns_extended_bolus_last_synced_id, 0)
startId = 0
}
if (startId == lastEbId && dateUtil.now() - lastEbTime < 5000) return false if (startId == lastEbId && dateUtil.now() - lastEbTime < 5000) return false
lastEbId = startId lastEbId = startId
lastEbTime = dateUtil.now() lastEbTime = dateUtil.now()
appRepository.getNextSyncElementExtendedBolus(startId).blockingGet()?.let { eb -> appRepository.getNextSyncElementExtendedBolus(startId).blockingGet()?.let { eb ->
aapsLogger.info(LTag.DATABASE, "Loading ExtendedBolus data Start: $startId ID: ${eb.first.id} HistoryID: ${eb.second} ") aapsLogger.info(LTag.DATABASE, "Loading ExtendedBolus data Start: $startId ID: ${eb.first.id} HistoryID: ${eb.second} ")
profileFunction.getProfile(eb.first.timestamp)?.let { profile -> val profile = profileFunction.getProfile(eb.first.timestamp)
if (profile != null) {
when { when {
// without nsId = create new // without nsId = create new
eb.first.interfaceIDs.nightscoutId == null -> eb.first.interfaceIDs.nightscoutId == null ->
nsClientPlugin.nsClientService?.dbAdd("treatments", eb.first.toJson(profile, dateUtil, useAbsolute), DataSyncSelector.PairExtendedBolus(eb.first, eb.second)) nsClientPlugin.nsClientService?.dbAdd("treatments", eb.first.toJson(profile, dateUtil, useAbsolute), DataSyncSelector.PairExtendedBolus(eb.first, eb.second), "$startId/$lastDbId")
// with nsId = update // with nsId = update
eb.first.interfaceIDs.nightscoutId != null -> eb.first.interfaceIDs.nightscoutId != null ->
nsClientPlugin.nsClientService?.dbUpdate("treatments", eb.first.interfaceIDs.nightscoutId, eb.first.toJson(profile, dateUtil, useAbsolute), DataSyncSelector.PairExtendedBolus(eb.first, eb.second)) nsClientPlugin.nsClientService?.dbUpdate("treatments", eb.first.interfaceIDs.nightscoutId, eb.first.toJson(profile, dateUtil, useAbsolute), DataSyncSelector.PairExtendedBolus(eb.first, eb.second), "$startId/$lastDbId")
} }
return true return true
} ?: confirmLastExtendedBolusIdIfGreater(eb.second) } else {
confirmLastExtendedBolusIdIfGreater(eb.second)
lastEbId = -1
processChangedExtendedBolusesCompat()
}
} }
return false return false
} }
@ -453,7 +528,13 @@ class DataSyncSelectorImplementation @Inject constructor(
private var lastPsId = -1L private var lastPsId = -1L
private var lastPsTime = -1L private var lastPsTime = -1L
override fun processChangedProfileSwitchesCompat(): Boolean { override fun processChangedProfileSwitchesCompat(): Boolean {
val startId = sp.getLong(R.string.key_ns_profile_switch_last_synced_id, 0) val lastDbIdWrapped = appRepository.getLastProfileSwitchIdWrapped().blockingGet()
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
var startId = sp.getLong(R.string.key_ns_profile_switch_last_synced_id, 0)
if (startId > lastDbId) {
sp.putLong(R.string.key_ns_profile_switch_last_synced_id, 0)
startId = 0
}
if (startId == lastPsId && dateUtil.now() - lastPsTime < 5000) return false if (startId == lastPsId && dateUtil.now() - lastPsTime < 5000) return false
lastPsId = startId lastPsId = startId
lastPsTime = dateUtil.now() lastPsTime = dateUtil.now()
@ -462,10 +543,10 @@ class DataSyncSelectorImplementation @Inject constructor(
when { when {
// without nsId = create new // without nsId = create new
ps.first.interfaceIDs.nightscoutId == null -> ps.first.interfaceIDs.nightscoutId == null ->
nsClientPlugin.nsClientService?.dbAdd("treatments", ps.first.toJson(dateUtil), DataSyncSelector.PairProfileSwitch(ps.first, ps.second)) nsClientPlugin.nsClientService?.dbAdd("treatments", ps.first.toJson(dateUtil), DataSyncSelector.PairProfileSwitch(ps.first, ps.second), "$startId/$lastDbId")
// with nsId = update // with nsId = update
ps.first.interfaceIDs.nightscoutId != null -> ps.first.interfaceIDs.nightscoutId != null ->
nsClientPlugin.nsClientService?.dbUpdate("treatments", ps.first.interfaceIDs.nightscoutId, ps.first.toJson(dateUtil), DataSyncSelector.PairProfileSwitch(ps.first, ps.second)) nsClientPlugin.nsClientService?.dbUpdate("treatments", ps.first.interfaceIDs.nightscoutId, ps.first.toJson(dateUtil), DataSyncSelector.PairProfileSwitch(ps.first, ps.second), "$startId/$lastDbId")
} }
return true return true
} }
@ -483,6 +564,6 @@ class DataSyncSelectorImplementation @Inject constructor(
localProfilePlugin.createProfileStore() localProfilePlugin.createProfileStore()
val profileJson = localProfilePlugin.profile?.data ?: return val profileJson = localProfilePlugin.profile?.data ?: return
if (lastChange > lastSync) if (lastChange > lastSync)
nsClientPlugin.nsClientService?.dbAdd("profile", profileJson, DataSyncSelector.PairProfileStore(profileJson, dateUtil.now())) nsClientPlugin.nsClientService?.dbAdd("profile", profileJson, DataSyncSelector.PairProfileStore(profileJson, dateUtil.now()), "")
} }
} }

View file

@ -206,7 +206,7 @@ class NSClientAddAckWorker(
.blockingGet() .blockingGet()
rxBus.send(EventNSClientNewLog("DBADD", "Acked ExtendedBolus " + pair.value.interfaceIDs.nightscoutId)) rxBus.send(EventNSClientNewLog("DBADD", "Acked ExtendedBolus " + pair.value.interfaceIDs.nightscoutId))
// Send new if waiting // Send new if waiting
dataSyncSelector.processChangedTemporaryBasalsCompat() dataSyncSelector.processChangedExtendedBolusesCompat()
} }
is PairProfileSwitch -> { is PairProfileSwitch -> {
@ -225,7 +225,7 @@ class NSClientAddAckWorker(
.blockingGet() .blockingGet()
rxBus.send(EventNSClientNewLog("DBADD", "Acked ProfileSwitch " + pair.value.interfaceIDs.nightscoutId)) rxBus.send(EventNSClientNewLog("DBADD", "Acked ProfileSwitch " + pair.value.interfaceIDs.nightscoutId))
// Send new if waiting // Send new if waiting
dataSyncSelector.processChangedTemporaryBasalsCompat() dataSyncSelector.processChangedProfileSwitchesCompat()
} }
is DeviceStatus -> { is DeviceStatus -> {

View file

@ -594,7 +594,7 @@ class NSClientService : DaggerService() {
} }
} }
fun dbUpdate(collection: String, _id: String?, data: JSONObject?, originalObject: Any) { fun dbUpdate(collection: String, _id: String?, data: JSONObject?, originalObject: Any, progress: String) {
try { try {
if (_id == null) return if (_id == null) return
if (!isConnected || !hasWriteAuth) return if (!isConnected || !hasWriteAuth) return
@ -603,20 +603,20 @@ class NSClientService : DaggerService() {
message.put("_id", _id) message.put("_id", _id)
message.put("data", data) message.put("data", data)
socket?.emit("dbUpdate", message, NSUpdateAck("dbUpdate", _id, aapsLogger, rxBus, originalObject)) socket?.emit("dbUpdate", message, NSUpdateAck("dbUpdate", _id, aapsLogger, rxBus, originalObject))
rxBus.send(EventNSClientNewLog("DBUPDATE $collection", "Sent " + originalObject.javaClass.simpleName + " " + _id)) rxBus.send(EventNSClientNewLog("DBUPDATE $collection", "Sent " + originalObject.javaClass.simpleName + " " + _id + " " + progress))
} catch (e: JSONException) { } catch (e: JSONException) {
aapsLogger.error("Unhandled exception", e) aapsLogger.error("Unhandled exception", e)
} }
} }
fun dbAdd(collection: String, data: JSONObject, originalObject: Any) { fun dbAdd(collection: String, data: JSONObject, originalObject: Any, progress: String) {
try { try {
if (!isConnected || !hasWriteAuth) return if (!isConnected || !hasWriteAuth) return
val message = JSONObject() val message = JSONObject()
message.put("collection", collection) message.put("collection", collection)
message.put("data", data) message.put("data", data)
socket?.emit("dbAdd", message, NSAddAck(aapsLogger, rxBus, originalObject)) socket?.emit("dbAdd", message, NSAddAck(aapsLogger, rxBus, originalObject))
rxBus.send(EventNSClientNewLog("DBADD $collection", "Sent " + originalObject.javaClass.simpleName + " " + data)) rxBus.send(EventNSClientNewLog("DBADD $collection", "Sent " + originalObject.javaClass.simpleName + " " + data + " " + progress))
} catch (e: JSONException) { } catch (e: JSONException) {
aapsLogger.error("Unhandled exception", e) aapsLogger.error("Unhandled exception", e)
} }

View file

@ -78,6 +78,11 @@ open class AppRepository @Inject internal constructor(
database.glucoseValueDao.getModifiedFrom(lastId) database.glucoseValueDao.getModifiedFrom(lastId)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
fun getLastGlucoseValueIdWrapped(): Single<ValueWrapper<Long>> =
database.glucoseValueDao.getLastId()
.subscribeOn(Schedulers.io())
.toWrappedSingle()
/* /*
* returns a Pair of the next entity to sync and the ID of the "update". * 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 * The update id might either be the entry id itself if it is a new entry - or the id
@ -151,6 +156,11 @@ open class AppRepository @Inject internal constructor(
fun deleteAllTempTargetEntries() = fun deleteAllTempTargetEntries() =
database.temporaryTargetDao.deleteAllEntries() database.temporaryTargetDao.deleteAllEntries()
fun getLastTempTargetIdWrapped(): Single<ValueWrapper<Long>> =
database.temporaryTargetDao.getLastId()
.subscribeOn(Schedulers.io())
.toWrappedSingle()
// USER ENTRY // USER ENTRY
fun getAllUserEntries(): Single<List<UserEntry>> = fun getAllUserEntries(): Single<List<UserEntry>> =
database.userEntryDao.getAll() database.userEntryDao.getAll()
@ -217,6 +227,11 @@ open class AppRepository @Inject internal constructor(
.map { if (!ascending) it.reversed() else it } .map { if (!ascending) it.reversed() else it }
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
fun getLastProfileSwitchIdWrapped(): Single<ValueWrapper<Long>> =
database.profileSwitchDao.getLastId()
.subscribeOn(Schedulers.io())
.toWrappedSingle()
// EFFECTIVE PROFILE SWITCH // EFFECTIVE PROFILE SWITCH
/* /*
* returns a Pair of the next entity to sync and the ID of the "update". * returns a Pair of the next entity to sync and the ID of the "update".
@ -267,6 +282,11 @@ open class AppRepository @Inject internal constructor(
fun deleteAllEffectiveProfileSwitches() = fun deleteAllEffectiveProfileSwitches() =
database.effectiveProfileSwitchDao.deleteAllEntries() database.effectiveProfileSwitchDao.deleteAllEntries()
fun getLastEffectiveProfileSwitchIdWrapped(): Single<ValueWrapper<Long>> =
database.effectiveProfileSwitchDao.getLastId()
.subscribeOn(Schedulers.io())
.toWrappedSingle()
// THERAPY EVENT // THERAPY EVENT
/* /*
* returns a Pair of the next entity to sync and the ID of the "update". * returns a Pair of the next entity to sync and the ID of the "update".
@ -329,6 +349,11 @@ open class AppRepository @Inject internal constructor(
database.therapyEventDao.compatGetTherapyEventDataFromToTime(from, to) database.therapyEventDao.compatGetTherapyEventDataFromToTime(from, to)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
fun getLastTherapyEventIdWrapped(): Single<ValueWrapper<Long>> =
database.therapyEventDao.getLastId()
.subscribeOn(Schedulers.io())
.toWrappedSingle()
// FOOD // FOOD
/* /*
* returns a Pair of the next entity to sync and the ID of the "update". * returns a Pair of the next entity to sync and the ID of the "update".
@ -360,6 +385,11 @@ open class AppRepository @Inject internal constructor(
fun deleteAllFoods() = fun deleteAllFoods() =
database.foodDao.deleteAllEntries() database.foodDao.deleteAllEntries()
fun getLastFoodIdWrapped(): Single<ValueWrapper<Long>> =
database.foodDao.getLastId()
.subscribeOn(Schedulers.io())
.toWrappedSingle()
// BOLUS // BOLUS
/* /*
* returns a Pair of the next entity to sync and the ID of the "update". * returns a Pair of the next entity to sync and the ID of the "update".
@ -421,6 +451,10 @@ open class AppRepository @Inject internal constructor(
fun deleteAllBoluses() = fun deleteAllBoluses() =
database.bolusDao.deleteAllEntries() database.bolusDao.deleteAllEntries()
fun getLastBolusIdWrapped(): Single<ValueWrapper<Long>> =
database.bolusDao.getLastId()
.subscribeOn(Schedulers.io())
.toWrappedSingle()
// CARBS // CARBS
private fun expandCarbs(carbs: Carbs): List<Carbs> = private fun expandCarbs(carbs: Carbs): List<Carbs> =
@ -529,6 +563,11 @@ open class AppRepository @Inject internal constructor(
fun deleteAllCarbs() = fun deleteAllCarbs() =
database.carbsDao.deleteAllEntries() database.carbsDao.deleteAllEntries()
fun getLastCarbsIdWrapped(): Single<ValueWrapper<Long>> =
database.carbsDao.getLastId()
.subscribeOn(Schedulers.io())
.toWrappedSingle()
// BOLUS CALCULATOR RESULT // BOLUS CALCULATOR RESULT
/* /*
* returns a Pair of the next entity to sync and the ID of the "update". * returns a Pair of the next entity to sync and the ID of the "update".
@ -566,6 +605,11 @@ open class AppRepository @Inject internal constructor(
fun deleteAllBolusCalculatorResults() = fun deleteAllBolusCalculatorResults() =
database.bolusCalculatorResultDao.deleteAllEntries() database.bolusCalculatorResultDao.deleteAllEntries()
fun getLastBolusCalculatorResultIdWrapped(): Single<ValueWrapper<Long>> =
database.bolusCalculatorResultDao.getLastId()
.subscribeOn(Schedulers.io())
.toWrappedSingle()
// DEVICE STATUS // DEVICE STATUS
fun insert(deviceStatus: DeviceStatus): Long = fun insert(deviceStatus: DeviceStatus): Long =
database.deviceStatusDao.insert(deviceStatus) database.deviceStatusDao.insert(deviceStatus)
@ -586,6 +630,11 @@ open class AppRepository @Inject internal constructor(
database.deviceStatusDao.getModifiedFrom(lastId) database.deviceStatusDao.getModifiedFrom(lastId)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
fun getLastDeviceStatusIdWrapped(): Single<ValueWrapper<Long>> =
database.deviceStatusDao.getLastId()
.subscribeOn(Schedulers.io())
.toWrappedSingle()
// TEMPORARY BASAL // TEMPORARY BASAL
/* /*
* returns a Pair of the next entity to sync and the ID of the "update". * returns a Pair of the next entity to sync and the ID of the "update".
@ -643,6 +692,11 @@ open class AppRepository @Inject internal constructor(
fun getOldestTemporaryBasalRecord(): TemporaryBasal? = fun getOldestTemporaryBasalRecord(): TemporaryBasal? =
database.temporaryBasalDao.getOldestRecord() database.temporaryBasalDao.getOldestRecord()
fun getLastTemporaryBasalIdWrapped(): Single<ValueWrapper<Long>> =
database.temporaryBasalDao.getLastId()
.subscribeOn(Schedulers.io())
.toWrappedSingle()
// EXTENDED BOLUS // EXTENDED BOLUS
/* /*
* returns a Pair of the next entity to sync and the ID of the "update". * returns a Pair of the next entity to sync and the ID of the "update".
@ -707,6 +761,10 @@ open class AppRepository @Inject internal constructor(
.map { if (!ascending) it.reversed() else it } .map { if (!ascending) it.reversed() else it }
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
fun getLastExtendedBolusIdWrapped(): Single<ValueWrapper<Long>> =
database.extendedBolusDao.getLastId()
.subscribeOn(Schedulers.io())
.toWrappedSingle()
} }
@Suppress("USELESS_CAST") @Suppress("USELESS_CAST")

View file

@ -18,6 +18,9 @@ internal interface BolusCalculatorResultDao : TraceableDao<BolusCalculatorResult
override fun deleteAllEntries() override fun deleteAllEntries()
@Query("SELECT id FROM $TABLE_BOLUS_CALCULATOR_RESULTS ORDER BY id DESC limit 1")
fun getLastId(): Maybe<Long>
@Query("SELECT * FROM $TABLE_BOLUS_CALCULATOR_RESULTS WHERE isValid = 1 AND timestamp >= :timestamp AND referenceId IS NULL ORDER BY id DESC") @Query("SELECT * FROM $TABLE_BOLUS_CALCULATOR_RESULTS WHERE isValid = 1 AND timestamp >= :timestamp AND referenceId IS NULL ORDER BY id DESC")
fun getBolusCalculatorResultsFromTime(timestamp: Long): Single<List<BolusCalculatorResult>> fun getBolusCalculatorResultsFromTime(timestamp: Long): Single<List<BolusCalculatorResult>>

View file

@ -18,6 +18,9 @@ internal interface BolusDao : TraceableDao<Bolus> {
@Query("DELETE FROM $TABLE_BOLUSES") @Query("DELETE FROM $TABLE_BOLUSES")
override fun deleteAllEntries() override fun deleteAllEntries()
@Query("SELECT id FROM $TABLE_BOLUSES ORDER BY id DESC limit 1")
fun getLastId(): Maybe<Long>
@Query("SELECT * FROM $TABLE_BOLUSES WHERE timestamp = :timestamp AND referenceId IS NULL") @Query("SELECT * FROM $TABLE_BOLUSES WHERE timestamp = :timestamp AND referenceId IS NULL")
fun findByTimestamp(timestamp: Long): Bolus? fun findByTimestamp(timestamp: Long): Bolus?

View file

@ -17,6 +17,9 @@ internal interface CarbsDao : TraceableDao<Carbs> {
@Query("DELETE FROM $TABLE_CARBS") @Query("DELETE FROM $TABLE_CARBS")
override fun deleteAllEntries() override fun deleteAllEntries()
@Query("SELECT id FROM $TABLE_CARBS ORDER BY id DESC limit 1")
fun getLastId(): Maybe<Long>
@Query("SELECT * FROM $TABLE_CARBS WHERE nightscoutId = :nsId AND referenceId IS NULL") @Query("SELECT * FROM $TABLE_CARBS WHERE nightscoutId = :nsId AND referenceId IS NULL")
fun findByNSId(nsId: String): Carbs? fun findByNSId(nsId: String): Carbs?

View file

@ -25,6 +25,9 @@ internal interface DeviceStatusDao {
@Query("DELETE FROM $TABLE_DEVICE_STATUS") @Query("DELETE FROM $TABLE_DEVICE_STATUS")
fun deleteAllEntries() fun deleteAllEntries()
@Query("SELECT id FROM $TABLE_DEVICE_STATUS ORDER BY id DESC limit 1")
fun getLastId(): Maybe<Long>
@Query("DELETE FROM $TABLE_DEVICE_STATUS WHERE id NOT IN (SELECT MAX(id) FROM $TABLE_DEVICE_STATUS)") @Query("DELETE FROM $TABLE_DEVICE_STATUS WHERE id NOT IN (SELECT MAX(id) FROM $TABLE_DEVICE_STATUS)")
fun deleteAllEntriesExceptLast() fun deleteAllEntriesExceptLast()

View file

@ -17,6 +17,9 @@ internal interface EffectiveProfileSwitchDao : TraceableDao<EffectiveProfileSwit
@Query("DELETE FROM $TABLE_EFFECTIVE_PROFILE_SWITCHES") @Query("DELETE FROM $TABLE_EFFECTIVE_PROFILE_SWITCHES")
override fun deleteAllEntries() override fun deleteAllEntries()
@Query("SELECT id FROM $TABLE_EFFECTIVE_PROFILE_SWITCHES ORDER BY id DESC limit 1")
fun getLastId(): Maybe<Long>
@Query("SELECT * FROM $TABLE_EFFECTIVE_PROFILE_SWITCHES WHERE isValid = 1 AND referenceId IS NULL ORDER BY id ASC LIMIT 1") @Query("SELECT * FROM $TABLE_EFFECTIVE_PROFILE_SWITCHES WHERE isValid = 1 AND referenceId IS NULL ORDER BY id ASC LIMIT 1")
fun getOldestEffectiveProfileSwitchRecord(): EffectiveProfileSwitch? fun getOldestEffectiveProfileSwitchRecord(): EffectiveProfileSwitch?

View file

@ -18,6 +18,9 @@ internal interface ExtendedBolusDao : TraceableDao<ExtendedBolus> {
@Query("DELETE FROM $TABLE_EXTENDED_BOLUSES") @Query("DELETE FROM $TABLE_EXTENDED_BOLUSES")
override fun deleteAllEntries() override fun deleteAllEntries()
@Query("SELECT id FROM $TABLE_EXTENDED_BOLUSES ORDER BY id DESC limit 1")
fun getLastId(): Maybe<Long>
@Query("SELECT * FROM $TABLE_EXTENDED_BOLUSES WHERE timestamp = :timestamp AND referenceId IS NULL") @Query("SELECT * FROM $TABLE_EXTENDED_BOLUSES WHERE timestamp = :timestamp AND referenceId IS NULL")
fun findByTimestamp(timestamp: Long): ExtendedBolus? fun findByTimestamp(timestamp: Long): ExtendedBolus?

View file

@ -17,6 +17,9 @@ internal interface FoodDao : TraceableDao<Food> {
@Query("DELETE FROM $TABLE_FOODS") @Query("DELETE FROM $TABLE_FOODS")
override fun deleteAllEntries() override fun deleteAllEntries()
@Query("SELECT id FROM $TABLE_FOODS ORDER BY id DESC limit 1")
fun getLastId(): Maybe<Long>
@Query("SELECT * FROM $TABLE_FOODS WHERE nightscoutId = :nsId AND referenceId IS NULL") @Query("SELECT * FROM $TABLE_FOODS WHERE nightscoutId = :nsId AND referenceId IS NULL")
fun findByNSId(nsId: String): Food? fun findByNSId(nsId: String): Food?

View file

@ -16,6 +16,9 @@ internal interface GlucoseValueDao : TraceableDao<GlucoseValue> {
@Query("DELETE FROM $TABLE_GLUCOSE_VALUES") @Query("DELETE FROM $TABLE_GLUCOSE_VALUES")
override fun deleteAllEntries() override fun deleteAllEntries()
@Query("SELECT id FROM $TABLE_GLUCOSE_VALUES ORDER BY id DESC limit 1")
fun getLastId(): Maybe<Long>
@Query("SELECT * FROM $TABLE_GLUCOSE_VALUES WHERE nightscoutId = :nsId AND referenceId IS NULL") @Query("SELECT * FROM $TABLE_GLUCOSE_VALUES WHERE nightscoutId = :nsId AND referenceId IS NULL")
fun findByNSIdMaybe(nsId: String): Maybe<GlucoseValue> fun findByNSIdMaybe(nsId: String): Maybe<GlucoseValue>

View file

@ -19,6 +19,9 @@ internal interface ProfileSwitchDao : ProfileSwitchDaoWorkaround {
@Query("DELETE FROM $TABLE_PROFILE_SWITCHES") @Query("DELETE FROM $TABLE_PROFILE_SWITCHES")
override fun deleteAllEntries() override fun deleteAllEntries()
@Query("SELECT id FROM $TABLE_PROFILE_SWITCHES ORDER BY id DESC limit 1")
fun getLastId(): Maybe<Long>
@Query("SELECT * FROM $TABLE_PROFILE_SWITCHES WHERE timestamp = :timestamp AND referenceId IS NULL") @Query("SELECT * FROM $TABLE_PROFILE_SWITCHES WHERE timestamp = :timestamp AND referenceId IS NULL")
fun findByTimestamp(timestamp: Long): ProfileSwitch? fun findByTimestamp(timestamp: Long): ProfileSwitch?

View file

@ -18,6 +18,9 @@ internal interface TemporaryBasalDao : TraceableDao<TemporaryBasal> {
@Query("DELETE FROM $TABLE_TEMPORARY_BASALS") @Query("DELETE FROM $TABLE_TEMPORARY_BASALS")
override fun deleteAllEntries() override fun deleteAllEntries()
@Query("SELECT id FROM $TABLE_TEMPORARY_BASALS ORDER BY id DESC limit 1")
fun getLastId(): Maybe<Long>
@Query("SELECT * FROM $TABLE_TEMPORARY_BASALS WHERE temporaryId = :temporaryId") @Query("SELECT * FROM $TABLE_TEMPORARY_BASALS WHERE temporaryId = :temporaryId")
fun findByTempId(temporaryId: Long): TemporaryBasal? fun findByTempId(temporaryId: Long): TemporaryBasal?

View file

@ -17,6 +17,9 @@ internal interface TemporaryTargetDao : TraceableDao<TemporaryTarget> {
@Query("DELETE FROM $TABLE_TEMPORARY_TARGETS") @Query("DELETE FROM $TABLE_TEMPORARY_TARGETS")
override fun deleteAllEntries() override fun deleteAllEntries()
@Query("SELECT id FROM $TABLE_TEMPORARY_TARGETS ORDER BY id DESC limit 1")
fun getLastId(): Maybe<Long>
@Query("SELECT * FROM $TABLE_TEMPORARY_TARGETS WHERE nightscoutId = :nsId AND referenceId IS NULL") @Query("SELECT * FROM $TABLE_TEMPORARY_TARGETS WHERE nightscoutId = :nsId AND referenceId IS NULL")
fun findByNSId(nsId: String): TemporaryTarget? fun findByNSId(nsId: String): TemporaryTarget?

View file

@ -16,6 +16,9 @@ internal interface TherapyEventDao : TraceableDao<TherapyEvent> {
@Query("DELETE FROM $TABLE_THERAPY_EVENTS") @Query("DELETE FROM $TABLE_THERAPY_EVENTS")
override fun deleteAllEntries() override fun deleteAllEntries()
@Query("SELECT id FROM $TABLE_THERAPY_EVENTS ORDER BY id DESC limit 1")
fun getLastId(): Maybe<Long>
@Query("SELECT * FROM $TABLE_THERAPY_EVENTS WHERE type = :type AND timestamp = :timestamp AND referenceId IS NULL") @Query("SELECT * FROM $TABLE_THERAPY_EVENTS WHERE type = :type AND timestamp = :timestamp AND referenceId IS NULL")
fun findByTimestamp(type: TherapyEvent.Type, timestamp: Long): TherapyEvent? fun findByTimestamp(type: TherapyEvent.Type, timestamp: Long): TherapyEvent?