From 0dd1254bf49d5decbd5398fa195353b97715cd36 Mon Sep 17 00:00:00 2001 From: Sulka Haro Date: Mon, 28 Sep 2020 09:36:21 +0300 Subject: [PATCH 1/3] Bump version to 14.0.6 --- npm-shrinkwrap.json | 2 +- package.json | 2 +- swagger.json | 2 +- swagger.yaml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 3ba1035c896..14b8d343cf4 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -1,6 +1,6 @@ { "name": "nightscout", - "version": "14.0.5", + "version": "14.0.6", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 7ae6694563a..ec94894a060 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nightscout", - "version": "14.0.5", + "version": "14.0.6", "description": "Nightscout acts as a web-based CGM (Continuous Glucose Montinor) to allow multiple caregivers to remotely view a patients glucose data in realtime.", "license": "AGPL-3.0", "author": "Nightscout Team", diff --git a/swagger.json b/swagger.json index 5d3504ecf60..83f28a0469f 100755 --- a/swagger.json +++ b/swagger.json @@ -8,7 +8,7 @@ "info": { "title": "Nightscout API", "description": "Own your DData with the Nightscout API", - "version": "14.0.5", + "version": "14.0.6", "license": { "name": "AGPL 3", "url": "https://www.gnu.org/licenses/agpl.txt" diff --git a/swagger.yaml b/swagger.yaml index 1bd4a02a964..7429d96a309 100755 --- a/swagger.yaml +++ b/swagger.yaml @@ -4,7 +4,7 @@ servers: info: title: Nightscout API description: Own your DData with the Nightscout API - version: 14.0.5 + version: 14.0.6 license: name: AGPL 3 url: 'https://www.gnu.org/licenses/agpl.txt' From a8b53f54e5de973f98e1a8a512a88be8e167375b Mon Sep 17 00:00:00 2001 From: Sulka Haro Date: Mon, 28 Sep 2020 10:51:27 +0300 Subject: [PATCH 2/3] Support uploading device statuses in batches (#6147) * Support uploading device statuses in batches * Correctly report batch insertion results --- lib/server/devicestatus.js | 70 ++++++++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 25 deletions(-) diff --git a/lib/server/devicestatus.js b/lib/server/devicestatus.js index e228f5b372c..bf71437d646 100644 --- a/lib/server/devicestatus.js +++ b/lib/server/devicestatus.js @@ -5,34 +5,51 @@ var find_options = require('./query'); function storage (collection, ctx) { - function create (obj, fn) { - - // Normalize all dates to UTC - const d = moment(obj.created_at).isValid() ? moment.parseZone(obj.created_at) : moment(); - obj.created_at = d.toISOString(); - obj.utcOffset = d.utcOffset(); - - api().insertOne(obj, function(err, results) { - if (err !== null && err.message) { - console.log('Error inserting the device status object', err.message); - fn(err.message, null); - return; - } + function create (statuses, fn) { - if (!err) { + if (!Array.isArray(statuses)) { statuses = [statuses]; } - if (!obj._id) obj._id = results.insertedIds[0]._id; + const r = []; + let errorOccurred = false; - ctx.bus.emit('data-update', { - type: 'devicestatus' - , op: 'update' - , changes: ctx.ddata.processRawDataForRuntime([obj]) - }); - } + for (let i = 0; i < statuses.length; i++) { - fn(null, results.ops); - ctx.bus.emit('data-received'); - }); + const obj = statuses[i]; + + if (errorOccurred) return; + + // Normalize all dates to UTC + const d = moment(obj.created_at).isValid() ? moment.parseZone(obj.created_at) : moment(); + obj.created_at = d.toISOString(); + obj.utcOffset = d.utcOffset(); + + api().insertOne(obj, function(err, results) { + if (err !== null && err.message) { + console.log('Error inserting the device status object', err.message); + errorOccurred = true; + fn(err.message, null); + return; + } + + if (!err) { + + if (!obj._id) obj._id = results.insertedIds[0]._id; + r.push(obj); + + ctx.bus.emit('data-update', { + type: 'devicestatus' + , op: 'update' + , changes: ctx.ddata.processRawDataForRuntime([obj]) + }); + + // Last object! Return results + if (i == statuses.length - 1) { + fn(null, r); + ctx.bus.emit('data-received'); + } + } + }); + }; } function last (fn) { @@ -109,7 +126,10 @@ function storage (collection, ctx) { api.aggregate = require('./aggregate')({}, api); api.indexedFields = [ 'created_at' - + + + + , 'NSCLIENT_ID' ]; return api; From 48f5578e8a0b13341ad0e781910f70d93764b86c Mon Sep 17 00:00:00 2001 From: Sulka Haro Date: Mon, 28 Sep 2020 11:12:42 +0300 Subject: [PATCH 3/3] Make empty cache detection a bit more aggressive to account for cache flush and data insert happening concurrently --- lib/server/cache.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/server/cache.js b/lib/server/cache.js index 1b2576ce029..88e5f77ca02 100644 --- a/lib/server/cache.js +++ b/lib/server/cache.js @@ -53,7 +53,7 @@ function cache (env, ctx) { } data.isEmpty = (datatype) => { - return data[datatype].length == 0; + return data[datatype].length < 20; } data.getData = (datatype) => {