make processChangedGlucoseValuesCompat tailrec
This commit is contained in:
parent
6ed9024769
commit
b330e7af00
2 changed files with 9 additions and 8 deletions
|
@ -419,7 +419,7 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
|
||||
//private var lastGvId = -1L
|
||||
//private var lastGvTime = -1L
|
||||
override fun processChangedGlucoseValuesCompat(): Boolean {
|
||||
override tailrec fun processChangedGlucoseValuesCompat() {
|
||||
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)
|
||||
|
@ -431,6 +431,7 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
//lastGvId = startId
|
||||
//lastGvTime = dateUtil.now()
|
||||
queueCounter.gvsRemaining = lastDbId - startId
|
||||
var tailCall = false
|
||||
appRepository.getNextSyncElementGlucoseValue(startId).blockingGet()?.let { gv ->
|
||||
aapsLogger.info(LTag.DATABASE, "Loading GlucoseValue data ID: ${gv.first.id} HistoryID: ${gv.second.id} ")
|
||||
if (activePlugin.activeBgSource.shouldUploadToNs(gv.first)) {
|
||||
|
@ -439,15 +440,14 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
gv.first.onlyNsIdAdded(gv.second) -> {
|
||||
confirmLastGlucoseValueIdIfGreater(gv.second.id)
|
||||
//lastGvId = -1
|
||||
processChangedGlucoseValuesCompat()
|
||||
aapsLogger.info(LTag.DATABASE, "Ignoring GlucoseValue. Only NS id changed ID: ${gv.first.id} HistoryID: ${gv.second.id} ")
|
||||
return false
|
||||
tailCall = true
|
||||
}
|
||||
// without nsId = create new
|
||||
gv.first.interfaceIDs.nightscoutId == null ->
|
||||
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 ->
|
||||
else -> // gv.first.interfaceIDs.nightscoutId != null
|
||||
nsClientPlugin.nsClientService?.dbUpdate(
|
||||
"entries",
|
||||
gv.first.interfaceIDs.nightscoutId,
|
||||
|
@ -456,15 +456,16 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
"$startId/$lastDbId"
|
||||
)
|
||||
}
|
||||
return true
|
||||
} else {
|
||||
confirmLastGlucoseValueIdIfGreater(gv.second.id)
|
||||
//lastGvId = -1
|
||||
tailCall = true
|
||||
}
|
||||
}
|
||||
if (tailCall) {
|
||||
processChangedGlucoseValuesCompat()
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
override fun confirmLastTherapyEventIdIfGreater(lastSynced: Long) {
|
||||
if (lastSynced > sp.getLong(R.string.key_ns_therapy_event_last_synced_id, 0)) {
|
||||
|
|
|
@ -49,7 +49,7 @@ interface DataSyncSelector {
|
|||
fun confirmLastGlucoseValueIdIfGreater(lastSynced: Long)
|
||||
fun changedGlucoseValues() : List<GlucoseValue>
|
||||
// Until NS v3
|
||||
fun processChangedGlucoseValuesCompat(): Boolean
|
||||
fun processChangedGlucoseValuesCompat()
|
||||
|
||||
fun confirmLastTherapyEventIdIfGreater(lastSynced: Long)
|
||||
fun changedTherapyEvents() : List<TherapyEvent>
|
||||
|
|
Loading…
Reference in a new issue