do not full_sync DeviceStatus

This commit is contained in:
Milos Kozak 2021-10-16 16:10:09 +02:00
parent 94cc26ffea
commit 6ad50d2979

View file

@ -28,7 +28,7 @@ class DataSyncSelectorImplementation @Inject constructor(
private val localProfilePlugin: LocalProfilePlugin
) : DataSyncSelector {
class QueueCounter (
class QueueCounter(
var bolusesRemaining: Long = 0L,
var carbsRemaining: Long = 0L,
var bcrRemaining: Long = 0L,
@ -90,7 +90,6 @@ class DataSyncSelectorImplementation @Inject constructor(
sp.remove(R.string.key_ns_bolus_last_synced_id)
sp.remove(R.string.key_ns_carbs_last_synced_id)
sp.remove(R.string.key_ns_bolus_calculator_result_last_synced_id)
sp.remove(R.string.key_ns_device_status_last_synced_id)
sp.remove(R.string.key_ns_temporary_basal_last_synced_id)
sp.remove(R.string.key_ns_extended_bolus_last_synced_id)
sp.remove(R.string.key_ns_therapy_event_last_synced_id)
@ -98,6 +97,9 @@ class DataSyncSelectorImplementation @Inject constructor(
sp.remove(R.string.key_ns_effective_profile_switch_last_synced_id)
sp.remove(R.string.key_ns_offline_event_last_synced_id)
sp.remove(R.string.key_ns_profile_store_last_synced_timestamp)
val lastDbIdWrapped = appRepository.getLastDeviceStatusIdWrapped().blockingGet()
if (lastDbIdWrapped is ValueWrapper.Existing) sp.putLong(R.string.key_ns_device_status_last_synced_id, lastDbIdWrapped.value)
else sp.remove(R.string.key_ns_device_status_last_synced_id)
}
override fun confirmLastBolusIdIfGreater(lastSynced: Long) {
@ -136,7 +138,7 @@ class DataSyncSelectorImplementation @Inject constructor(
aapsLogger.info(LTag.DATABASE, "Loading Bolus data Start: $startId ID: ${bolus.first.id} HistoryID: ${bolus.second.id} ")
when {
// only NsId changed, no need to upload
bolus.first.onlyNsIdAdded(bolus.second) -> {
bolus.first.onlyNsIdAdded(bolus.second) -> {
confirmLastBolusIdIfGreater(bolus.second.id)
//lastBolusId = -1
processChangedBolusesCompat()
@ -148,7 +150,13 @@ class DataSyncSelectorImplementation @Inject constructor(
nsClientPlugin.nsClientService?.dbAdd("treatments", bolus.first.toJson(true, dateUtil), DataSyncSelector.PairBolus(bolus.first, bolus.second.id), "$startId/$lastDbId")
// with nsId = update
bolus.first.interfaceIDs.nightscoutId != null ->
nsClientPlugin.nsClientService?.dbUpdate("treatments", bolus.first.interfaceIDs.nightscoutId, bolus.first.toJson(false, dateUtil), DataSyncSelector.PairBolus(bolus.first, bolus.second.id), "$startId/$lastDbId")
nsClientPlugin.nsClientService?.dbUpdate(
"treatments",
bolus.first.interfaceIDs.nightscoutId,
bolus.first.toJson(false, dateUtil),
DataSyncSelector.PairBolus(bolus.first, bolus.second.id),
"$startId/$lastDbId"
)
}
return true
}
@ -188,7 +196,7 @@ class DataSyncSelectorImplementation @Inject constructor(
aapsLogger.info(LTag.DATABASE, "Loading Carbs data Start: $startId ID: ${carb.first.id} HistoryID: ${carb.second.id} ")
when {
// only NsId changed, no need to upload
carb.first.onlyNsIdAdded(carb.second) -> {
carb.first.onlyNsIdAdded(carb.second) -> {
confirmLastCarbsIdIfGreater(carb.second.id)
//lastCarbsId = -1
processChangedCarbsCompat()
@ -200,7 +208,13 @@ class DataSyncSelectorImplementation @Inject constructor(
nsClientPlugin.nsClientService?.dbAdd("treatments", carb.first.toJson(true, dateUtil), DataSyncSelector.PairCarbs(carb.first, carb.second.id), "$startId/$lastDbId")
// with nsId = update
carb.first.interfaceIDs.nightscoutId != null ->
nsClientPlugin.nsClientService?.dbUpdate("treatments", carb.first.interfaceIDs.nightscoutId, carb.first.toJson(false, dateUtil), DataSyncSelector.PairCarbs(carb.first, carb.second.id), "$startId/$lastDbId")
nsClientPlugin.nsClientService?.dbUpdate(
"treatments",
carb.first.interfaceIDs.nightscoutId,
carb.first.toJson(false, dateUtil),
DataSyncSelector.PairCarbs(carb.first, carb.second.id),
"$startId/$lastDbId"
)
}
return true
}
@ -248,12 +262,19 @@ class DataSyncSelectorImplementation @Inject constructor(
return false
}
// without nsId = create new
bolusCalculatorResult.first.interfaceIDs.nightscoutId == null ->
nsClientPlugin.nsClientService?.dbAdd("treatments", bolusCalculatorResult.first.toJson(true, dateUtil), DataSyncSelector.PairBolusCalculatorResult(bolusCalculatorResult.first, bolusCalculatorResult.second.id), "$startId/$lastDbId")
bolusCalculatorResult.first.interfaceIDs.nightscoutId == null ->
nsClientPlugin.nsClientService?.dbAdd(
"treatments",
bolusCalculatorResult.first.toJson(true, dateUtil),
DataSyncSelector.PairBolusCalculatorResult(bolusCalculatorResult.first, bolusCalculatorResult.second.id),
"$startId/$lastDbId"
)
// with nsId = update
bolusCalculatorResult.first.interfaceIDs.nightscoutId != null ->
nsClientPlugin.nsClientService?.dbUpdate("treatments", bolusCalculatorResult.first.interfaceIDs.nightscoutId, bolusCalculatorResult.first.toJson(false, dateUtil),
DataSyncSelector.PairBolusCalculatorResult(bolusCalculatorResult.first, bolusCalculatorResult.second.id), "$startId/$lastDbId")
bolusCalculatorResult.first.interfaceIDs.nightscoutId != null ->
nsClientPlugin.nsClientService?.dbUpdate(
"treatments", bolusCalculatorResult.first.interfaceIDs.nightscoutId, bolusCalculatorResult.first.toJson(false, dateUtil),
DataSyncSelector.PairBolusCalculatorResult(bolusCalculatorResult.first, bolusCalculatorResult.second.id), "$startId/$lastDbId"
)
}
return true
}
@ -293,7 +314,7 @@ class DataSyncSelectorImplementation @Inject constructor(
aapsLogger.info(LTag.DATABASE, "Loading TemporaryTarget data Start: $startId ID: ${tt.first.id} HistoryID: ${tt.second.id} ")
when {
// only NsId changed, no need to upload
tt.first.onlyNsIdAdded(tt.second) -> {
tt.first.onlyNsIdAdded(tt.second) -> {
confirmLastTempTargetsIdIfGreater(tt.second.id)
//lastTtId = -1
processChangedTempTargetsCompat()
@ -302,10 +323,21 @@ class DataSyncSelectorImplementation @Inject constructor(
}
// without nsId = create new
tt.first.interfaceIDs.nightscoutId == null ->
nsClientPlugin.nsClientService?.dbAdd("treatments", tt.first.toJson(true, profileFunction.getUnits(), dateUtil), DataSyncSelector.PairTemporaryTarget(tt.first, tt.second.id), "$startId/$lastDbId")
nsClientPlugin.nsClientService?.dbAdd(
"treatments",
tt.first.toJson(true, profileFunction.getUnits(), dateUtil),
DataSyncSelector.PairTemporaryTarget(tt.first, tt.second.id),
"$startId/$lastDbId"
)
// existing with nsId = update
tt.first.interfaceIDs.nightscoutId != null ->
nsClientPlugin.nsClientService?.dbUpdate("treatments", tt.first.interfaceIDs.nightscoutId, tt.first.toJson(false, profileFunction.getUnits(), dateUtil), DataSyncSelector.PairTemporaryTarget(tt.first, tt.second.id), "$startId/$lastDbId")
nsClientPlugin.nsClientService?.dbUpdate(
"treatments",
tt.first.interfaceIDs.nightscoutId,
tt.first.toJson(false, profileFunction.getUnits(), dateUtil),
DataSyncSelector.PairTemporaryTarget(tt.first, tt.second.id),
"$startId/$lastDbId"
)
}
return true
}
@ -345,7 +377,7 @@ class DataSyncSelectorImplementation @Inject constructor(
aapsLogger.info(LTag.DATABASE, "Loading Food data Start: $startId ID: ${food.first.id} HistoryID: ${food.second} ")
when {
// only NsId changed, no need to upload
food.first.onlyNsIdAdded(food.second) -> {
food.first.onlyNsIdAdded(food.second) -> {
confirmLastFoodIdIfGreater(food.second.id)
//lastFoodId = -1
processChangedFoodsCompat()
@ -357,7 +389,13 @@ class DataSyncSelectorImplementation @Inject constructor(
nsClientPlugin.nsClientService?.dbAdd("food", food.first.toJson(true), DataSyncSelector.PairFood(food.first, food.second.id), "$startId/$lastDbId")
// with nsId = update
food.first.interfaceIDs.nightscoutId != null ->
nsClientPlugin.nsClientService?.dbUpdate("food", food.first.interfaceIDs.nightscoutId, food.first.toJson(false), DataSyncSelector.PairFood(food.first, food.second.id), "$startId/$lastDbId")
nsClientPlugin.nsClientService?.dbUpdate(
"food",
food.first.interfaceIDs.nightscoutId,
food.first.toJson(false),
DataSyncSelector.PairFood(food.first, food.second.id),
"$startId/$lastDbId"
)
}
return true
}
@ -398,7 +436,7 @@ class DataSyncSelectorImplementation @Inject constructor(
if (activePlugin.activeBgSource.shouldUploadToNs(gv.first)) {
when {
// only NsId changed, no need to upload
gv.first.onlyNsIdAdded(gv.second) -> {
gv.first.onlyNsIdAdded(gv.second) -> {
confirmLastGlucoseValueIdIfGreater(gv.second.id)
//lastGvId = -1
processChangedGlucoseValuesCompat()
@ -410,7 +448,13 @@ class DataSyncSelectorImplementation @Inject constructor(
nsClientPlugin.nsClientService?.dbAdd("entries", gv.first.toJson(true, dateUtil), DataSyncSelector.PairGlucoseValue(gv.first, gv.second.id), "$startId/$lastDbId")
// with nsId = update
gv.first.interfaceIDs.nightscoutId != null ->
nsClientPlugin.nsClientService?.dbUpdate("entries", gv.first.interfaceIDs.nightscoutId, gv.first.toJson(false, dateUtil), DataSyncSelector.PairGlucoseValue(gv.first, gv.second.id), "$startId/$lastDbId")
nsClientPlugin.nsClientService?.dbUpdate(
"entries",
gv.first.interfaceIDs.nightscoutId,
gv.first.toJson(false, dateUtil),
DataSyncSelector.PairGlucoseValue(gv.first, gv.second.id),
"$startId/$lastDbId"
)
}
return true
} else {
@ -455,7 +499,7 @@ class DataSyncSelectorImplementation @Inject constructor(
aapsLogger.info(LTag.DATABASE, "Loading TherapyEvents data Start: $startId ID: ${te.first.id} HistoryID: ${te.second} ")
when {
// only NsId changed, no need to upload
te.first.onlyNsIdAdded(te.second) -> {
te.first.onlyNsIdAdded(te.second) -> {
confirmLastTherapyEventIdIfGreater(te.second.id)
//lastTeId = -1
processChangedTherapyEventsCompat()
@ -467,7 +511,13 @@ class DataSyncSelectorImplementation @Inject constructor(
nsClientPlugin.nsClientService?.dbAdd("treatments", te.first.toJson(true, dateUtil), DataSyncSelector.PairTherapyEvent(te.first, te.second.id), "$startId/$lastDbId")
// nsId = update
te.first.interfaceIDs.nightscoutId != null ->
nsClientPlugin.nsClientService?.dbUpdate("treatments", te.first.interfaceIDs.nightscoutId, te.first.toJson(false, dateUtil), DataSyncSelector.PairTherapyEvent(te.first, te.second.id), "$startId/$lastDbId")
nsClientPlugin.nsClientService?.dbUpdate(
"treatments",
te.first.interfaceIDs.nightscoutId,
te.first.toJson(false, dateUtil),
DataSyncSelector.PairTherapyEvent(te.first, te.second.id),
"$startId/$lastDbId"
)
}
return true
}
@ -552,7 +602,7 @@ class DataSyncSelectorImplementation @Inject constructor(
if (profile != null) {
when {
// only NsId changed, no need to upload
tb.first.onlyNsIdAdded(tb.second) -> {
tb.first.onlyNsIdAdded(tb.second) -> {
confirmLastTemporaryBasalIdIfGreater(tb.second.id)
//lastTbrId = -1
processChangedTemporaryBasalsCompat()
@ -561,10 +611,21 @@ class DataSyncSelectorImplementation @Inject constructor(
}
// without nsId = create new
tb.first.interfaceIDs.nightscoutId == null ->
nsClientPlugin.nsClientService?.dbAdd("treatments", tb.first.toJson(true, profile, dateUtil, useAbsolute), DataSyncSelector.PairTemporaryBasal(tb.first, tb.second.id), "$startId/$lastDbId")
nsClientPlugin.nsClientService?.dbAdd(
"treatments",
tb.first.toJson(true, profile, dateUtil, useAbsolute),
DataSyncSelector.PairTemporaryBasal(tb.first, tb.second.id),
"$startId/$lastDbId"
)
// with nsId = update
tb.first.interfaceIDs.nightscoutId != null ->
nsClientPlugin.nsClientService?.dbUpdate("treatments", tb.first.interfaceIDs.nightscoutId, tb.first.toJson(false, profile, dateUtil, useAbsolute), DataSyncSelector.PairTemporaryBasal(tb.first, tb.second.id), "$startId/$lastDbId")
nsClientPlugin.nsClientService?.dbUpdate(
"treatments",
tb.first.interfaceIDs.nightscoutId,
tb.first.toJson(false, profile, dateUtil, useAbsolute),
DataSyncSelector.PairTemporaryBasal(tb.first, tb.second.id),
"$startId/$lastDbId"
)
}
return true
} else {
@ -612,7 +673,7 @@ class DataSyncSelectorImplementation @Inject constructor(
if (profile != null) {
when {
// only NsId changed, no need to upload
eb.first.onlyNsIdAdded(eb.second) -> {
eb.first.onlyNsIdAdded(eb.second) -> {
confirmLastExtendedBolusIdIfGreater(eb.second.id)
//lastEbId = -1
processChangedExtendedBolusesCompat()
@ -621,10 +682,21 @@ class DataSyncSelectorImplementation @Inject constructor(
}
// without nsId = create new
eb.first.interfaceIDs.nightscoutId == null ->
nsClientPlugin.nsClientService?.dbAdd("treatments", eb.first.toJson(true, profile, dateUtil, useAbsolute), DataSyncSelector.PairExtendedBolus(eb.first, eb.second.id), "$startId/$lastDbId")
nsClientPlugin.nsClientService?.dbAdd(
"treatments",
eb.first.toJson(true, profile, dateUtil, useAbsolute),
DataSyncSelector.PairExtendedBolus(eb.first, eb.second.id),
"$startId/$lastDbId"
)
// with nsId = update
eb.first.interfaceIDs.nightscoutId != null ->
nsClientPlugin.nsClientService?.dbUpdate("treatments", eb.first.interfaceIDs.nightscoutId, eb.first.toJson(false, profile, dateUtil, useAbsolute), DataSyncSelector.PairExtendedBolus(eb.first, eb.second.id), "$startId/$lastDbId")
nsClientPlugin.nsClientService?.dbUpdate(
"treatments",
eb.first.interfaceIDs.nightscoutId,
eb.first.toJson(false, profile, dateUtil, useAbsolute),
DataSyncSelector.PairExtendedBolus(eb.first, eb.second.id),
"$startId/$lastDbId"
)
}
return true
} else {
@ -668,7 +740,7 @@ class DataSyncSelectorImplementation @Inject constructor(
aapsLogger.info(LTag.DATABASE, "Loading ProfileSwitch data Start: $startId ID: ${ps.first.id} HistoryID: ${ps.second} ")
when {
// only NsId changed, no need to upload
ps.first.onlyNsIdAdded(ps.second) -> {
ps.first.onlyNsIdAdded(ps.second) -> {
confirmLastProfileSwitchIdIfGreater(ps.second.id)
//lastPsId = -1
processChangedProfileSwitchesCompat()
@ -680,7 +752,13 @@ class DataSyncSelectorImplementation @Inject constructor(
nsClientPlugin.nsClientService?.dbAdd("treatments", ps.first.toJson(true, dateUtil), DataSyncSelector.PairProfileSwitch(ps.first, ps.second.id), "$startId/$lastDbId")
// with nsId = update
ps.first.interfaceIDs.nightscoutId != null ->
nsClientPlugin.nsClientService?.dbUpdate("treatments", ps.first.interfaceIDs.nightscoutId, ps.first.toJson(false, dateUtil), DataSyncSelector.PairProfileSwitch(ps.first, ps.second.id), "$startId/$lastDbId")
nsClientPlugin.nsClientService?.dbUpdate(
"treatments",
ps.first.interfaceIDs.nightscoutId,
ps.first.toJson(false, dateUtil),
DataSyncSelector.PairProfileSwitch(ps.first, ps.second.id),
"$startId/$lastDbId"
)
}
return true
}
@ -719,7 +797,7 @@ class DataSyncSelectorImplementation @Inject constructor(
aapsLogger.info(LTag.DATABASE, "Loading EffectiveProfileSwitch data Start: $startId ID: ${ps.first.id} HistoryID: ${ps.second} ")
when {
// only NsId changed, no need to upload
ps.first.onlyNsIdAdded(ps.second) -> {
ps.first.onlyNsIdAdded(ps.second) -> {
confirmLastEffectiveProfileSwitchIdIfGreater(ps.second.id)
//lastEpsId = -1
processChangedEffectiveProfileSwitchesCompat()
@ -731,7 +809,13 @@ class DataSyncSelectorImplementation @Inject constructor(
nsClientPlugin.nsClientService?.dbAdd("treatments", ps.first.toJson(true, dateUtil), DataSyncSelector.PairEffectiveProfileSwitch(ps.first, ps.second.id), "$startId/$lastDbId")
// with nsId = update
ps.first.interfaceIDs.nightscoutId != null ->
nsClientPlugin.nsClientService?.dbUpdate("treatments", ps.first.interfaceIDs.nightscoutId, ps.first.toJson(false, dateUtil), DataSyncSelector.PairEffectiveProfileSwitch(ps.first, ps.second.id), "$startId/$lastDbId")
nsClientPlugin.nsClientService?.dbUpdate(
"treatments",
ps.first.interfaceIDs.nightscoutId,
ps.first.toJson(false, dateUtil),
DataSyncSelector.PairEffectiveProfileSwitch(ps.first, ps.second.id),
"$startId/$lastDbId"
)
}
return true
}
@ -771,7 +855,7 @@ class DataSyncSelectorImplementation @Inject constructor(
aapsLogger.info(LTag.DATABASE, "Loading OfflineEvent data Start: $startId ID: ${oe.first.id} HistoryID: ${oe.second} ")
when {
// only NsId changed, no need to upload
oe.first.onlyNsIdAdded(oe.second) -> {
oe.first.onlyNsIdAdded(oe.second) -> {
confirmLastOfflineEventIdIfGreater(oe.second.id)
//lastOeId = -1
processChangedOfflineEventsCompat()
@ -783,7 +867,13 @@ class DataSyncSelectorImplementation @Inject constructor(
nsClientPlugin.nsClientService?.dbAdd("treatments", oe.first.toJson(true, dateUtil), DataSyncSelector.PairOfflineEvent(oe.first, oe.second.id), "$startId/$lastDbId")
// existing with nsId = update
oe.first.interfaceIDs.nightscoutId != null ->
nsClientPlugin.nsClientService?.dbUpdate("treatments", oe.first.interfaceIDs.nightscoutId, oe.first.toJson(false, dateUtil), DataSyncSelector.PairOfflineEvent(oe.first, oe.second.id), "$startId/$lastDbId")
nsClientPlugin.nsClientService?.dbUpdate(
"treatments",
oe.first.interfaceIDs.nightscoutId,
oe.first.toJson(false, dateUtil),
DataSyncSelector.PairOfflineEvent(oe.first, oe.second.id),
"$startId/$lastDbId"
)
}
return true
}