diff --git a/core/interfaces/src/main/java/info/nightscout/interfaces/sync/NsClient.kt b/core/interfaces/src/main/java/info/nightscout/interfaces/sync/NsClient.kt index d495784c03..917bc5b8a3 100644 --- a/core/interfaces/src/main/java/info/nightscout/interfaces/sync/NsClient.kt +++ b/core/interfaces/src/main/java/info/nightscout/interfaces/sync/NsClient.kt @@ -21,6 +21,8 @@ interface NsClient : Sync { /** * Initiate new round of upload/download + * + * @param reason identification of caller */ fun resend(reason: String) diff --git a/core/ns-sdk/src/main/java/info/nightscout/sdk/networking/NightscoutRemoteService.kt b/core/ns-sdk/src/main/java/info/nightscout/sdk/networking/NightscoutRemoteService.kt index f61576bb19..a4bdc4ffff 100644 --- a/core/ns-sdk/src/main/java/info/nightscout/sdk/networking/NightscoutRemoteService.kt +++ b/core/ns-sdk/src/main/java/info/nightscout/sdk/networking/NightscoutRemoteService.kt @@ -41,7 +41,7 @@ internal interface NightscoutRemoteService { @GET("v3/entries?sort\$desc=date&type=sgv") suspend fun getSgvs(): Response>> - @GET("v3/entries") + @GET("v3/entries?sort=date") suspend fun getSgvsNewerThan(@Query(value = "date\$gt", encoded = true) date: Long, @Query("limit") limit: Int): Response>> @GET("v3/entries/history/{from}") @@ -56,7 +56,7 @@ internal interface NightscoutRemoteService { @DELETE("v3/entries/{identifier}") suspend fun deleteEntry(@Path("identifier") identifier: String): Response> - @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>> @GET("v3/treatments/history/{from}") diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/NSClientV3Plugin.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/NSClientV3Plugin.kt index 23df31acdc..5269b0d05c 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/NSClientV3Plugin.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/NSClientV3Plugin.kt @@ -170,7 +170,7 @@ class NSClientV3Plugin @Inject constructor( private val isAllowed get() = receiverDelegate.allowed 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 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 @@ -580,7 +580,10 @@ class NSClientV3Plugin @Inject constructor( **********************/ 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) else executeLoop("START $reason", forceNew = true) diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/workers/LoadBgWorker.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/workers/LoadBgWorker.kt index 62aaedfedd..1d2770df9e 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/workers/LoadBgWorker.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/workers/LoadBgWorker.kt @@ -64,7 +64,7 @@ class LoadBgWorker( // Objective0 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 - continueLoading = !(sgvs.size != NSClientV3Plugin.RECORDS_TO_LOAD || response.code == 304) + continueLoading = response.code != 304 nsIncomingDataProcessor.processSgvs(sgvs) } else { // End first load diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/workers/LoadTreatmentsWorker.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/workers/LoadTreatmentsWorker.kt index f428594fa3..ee62135d29 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/workers/LoadTreatmentsWorker.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/workers/LoadTreatmentsWorker.kt @@ -58,7 +58,7 @@ class LoadTreatmentsWorker( val action = if (isFirstLoad) "RCV-F" else "RCV" rxBus.send(EventNSClientNewLog("◄ $action", "${treatments.size} TRs from ${dateUtil.dateAndTimeAndSecondsString(lastLoaded)}")) // 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) } else { // End first load