NSCv3: resolve loading issues

This commit is contained in:
Milos Kozak 2023-09-13 13:15:58 +02:00
parent 608130c7ea
commit d379b769d3
5 changed files with 11 additions and 6 deletions

View file

@ -21,6 +21,8 @@ interface NsClient : Sync {
/** /**
* Initiate new round of upload/download * Initiate new round of upload/download
*
* @param reason identification of caller
*/ */
fun resend(reason: String) fun resend(reason: String)

View file

@ -41,7 +41,7 @@ internal interface NightscoutRemoteService {
@GET("v3/entries?sort\$desc=date&type=sgv") @GET("v3/entries?sort\$desc=date&type=sgv")
suspend fun getSgvs(): Response<NSResponse<List<RemoteEntry>>> suspend fun getSgvs(): Response<NSResponse<List<RemoteEntry>>>
@GET("v3/entries") @GET("v3/entries?sort=date")
suspend fun getSgvsNewerThan(@Query(value = "date\$gt", encoded = true) date: Long, @Query("limit") limit: Int): Response<NSResponse<List<RemoteEntry>>> suspend fun getSgvsNewerThan(@Query(value = "date\$gt", encoded = true) date: Long, @Query("limit") limit: Int): Response<NSResponse<List<RemoteEntry>>>
@GET("v3/entries/history/{from}") @GET("v3/entries/history/{from}")
@ -56,7 +56,7 @@ internal interface NightscoutRemoteService {
@DELETE("v3/entries/{identifier}") @DELETE("v3/entries/{identifier}")
suspend fun deleteEntry(@Path("identifier") identifier: String): Response<NSResponse<RemoteCreateUpdateResponse>> suspend fun deleteEntry(@Path("identifier") identifier: String): Response<NSResponse<RemoteCreateUpdateResponse>>
@GET("v3/treatments") @GET("v3/treatments?sort=date")
suspend fun getTreatmentsNewerThan(@Query(value = "created_at\$gt", encoded = true) createdAt: String, @Query("limit") limit: Int): Response<NSResponse<List<RemoteTreatment>>> suspend fun getTreatmentsNewerThan(@Query(value = "created_at\$gt", encoded = true) createdAt: String, @Query("limit") limit: Int): Response<NSResponse<List<RemoteTreatment>>>
@GET("v3/treatments/history/{from}") @GET("v3/treatments/history/{from}")

View file

@ -170,7 +170,7 @@ class NSClientV3Plugin @Inject constructor(
private val isAllowed get() = receiverDelegate.allowed private val isAllowed get() = receiverDelegate.allowed
private val blockingReason get() = receiverDelegate.blockingReason private val blockingReason get() = receiverDelegate.blockingReason
val maxAge = T.days(77).msecs() val maxAge = T.days(100).msecs()
internal var newestDataOnServer: LastModified? = null // timestamp of last modification for every collection provided by server internal var newestDataOnServer: LastModified? = null // timestamp of last modification for every collection provided by server
internal var lastLoadedSrvModified = LastModified(LastModified.Collections()) // max srvLastModified timestamp of last fetched data for every collection internal var lastLoadedSrvModified = LastModified(LastModified.Collections()) // max srvLastModified timestamp of last fetched data for every collection
internal var firstLoadContinueTimestamp = LastModified(LastModified.Collections()) // timestamp of last fetched data for every collection during initial load internal var firstLoadContinueTimestamp = LastModified(LastModified.Collections()) // timestamp of last fetched data for every collection during initial load
@ -580,7 +580,10 @@ class NSClientV3Plugin @Inject constructor(
**********************/ **********************/
override fun resend(reason: String) { override fun resend(reason: String) {
if (sp.getBoolean(info.nightscout.core.utils.R.string.key_ns_use_ws, true)) // If WS is enabled, download is triggered by changes in NS. Thus uploadOnly
// Exception is after reset to full sync (initialLoadFinished == false), where
// older data must be loaded directly and then continue over WS
if (sp.getBoolean(info.nightscout.core.utils.R.string.key_ns_use_ws, true) && initialLoadFinished)
executeUpload("START $reason", forceNew = true) executeUpload("START $reason", forceNew = true)
else else
executeLoop("START $reason", forceNew = true) executeLoop("START $reason", forceNew = true)

View file

@ -64,7 +64,7 @@ class LoadBgWorker(
// Objective0 // Objective0
sp.putBoolean(info.nightscout.core.utils.R.string.key_objectives_bg_is_available_in_ns, true) sp.putBoolean(info.nightscout.core.utils.R.string.key_objectives_bg_is_available_in_ns, true)
// Schedule processing of fetched data and continue of loading // Schedule processing of fetched data and continue of loading
continueLoading = !(sgvs.size != NSClientV3Plugin.RECORDS_TO_LOAD || response.code == 304) continueLoading = response.code != 304
nsIncomingDataProcessor.processSgvs(sgvs) nsIncomingDataProcessor.processSgvs(sgvs)
} else { } else {
// End first load // End first load

View file

@ -58,7 +58,7 @@ class LoadTreatmentsWorker(
val action = if (isFirstLoad) "RCV-F" else "RCV" val action = if (isFirstLoad) "RCV-F" else "RCV"
rxBus.send(EventNSClientNewLog("$action", "${treatments.size} TRs from ${dateUtil.dateAndTimeAndSecondsString(lastLoaded)}")) rxBus.send(EventNSClientNewLog("$action", "${treatments.size} TRs from ${dateUtil.dateAndTimeAndSecondsString(lastLoaded)}"))
// Schedule processing of fetched data and continue of loading // Schedule processing of fetched data and continue of loading
continueLoading = !(treatments.size != NSClientV3Plugin.RECORDS_TO_LOAD || response.code == 304) continueLoading = response.code != 304
nsIncomingDataProcessor.processTreatments(response.values) nsIncomingDataProcessor.processTreatments(response.values)
} else { } else {
// End first load // End first load