Skip to content

Commit 1818810

Browse files
authored
Merge pull request #6148 from nightscout/dev
Nightscout release 14.0.6 Liquorice
2 parents 9315b06 + 48f5578 commit 1818810

File tree

6 files changed

+50
-30
lines changed

6 files changed

+50
-30
lines changed

lib/server/cache.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function cache (env, ctx) {
5353
}
5454

5555
data.isEmpty = (datatype) => {
56-
return data[datatype].length == 0;
56+
return data[datatype].length < 20;
5757
}
5858

5959
data.getData = (datatype) => {

lib/server/devicestatus.js

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,51 @@ var find_options = require('./query');
55

66
function storage (collection, ctx) {
77

8-
function create (obj, fn) {
9-
10-
// Normalize all dates to UTC
11-
const d = moment(obj.created_at).isValid() ? moment.parseZone(obj.created_at) : moment();
12-
obj.created_at = d.toISOString();
13-
obj.utcOffset = d.utcOffset();
14-
15-
api().insertOne(obj, function(err, results) {
16-
if (err !== null && err.message) {
17-
console.log('Error inserting the device status object', err.message);
18-
fn(err.message, null);
19-
return;
20-
}
8+
function create (statuses, fn) {
219

22-
if (!err) {
10+
if (!Array.isArray(statuses)) { statuses = [statuses]; }
2311

24-
if (!obj._id) obj._id = results.insertedIds[0]._id;
12+
const r = [];
13+
let errorOccurred = false;
2514

26-
ctx.bus.emit('data-update', {
27-
type: 'devicestatus'
28-
, op: 'update'
29-
, changes: ctx.ddata.processRawDataForRuntime([obj])
30-
});
31-
}
15+
for (let i = 0; i < statuses.length; i++) {
3216

33-
fn(null, results.ops);
34-
ctx.bus.emit('data-received');
35-
});
17+
const obj = statuses[i];
18+
19+
if (errorOccurred) return;
20+
21+
// Normalize all dates to UTC
22+
const d = moment(obj.created_at).isValid() ? moment.parseZone(obj.created_at) : moment();
23+
obj.created_at = d.toISOString();
24+
obj.utcOffset = d.utcOffset();
25+
26+
api().insertOne(obj, function(err, results) {
27+
if (err !== null && err.message) {
28+
console.log('Error inserting the device status object', err.message);
29+
errorOccurred = true;
30+
fn(err.message, null);
31+
return;
32+
}
33+
34+
if (!err) {
35+
36+
if (!obj._id) obj._id = results.insertedIds[0]._id;
37+
r.push(obj);
38+
39+
ctx.bus.emit('data-update', {
40+
type: 'devicestatus'
41+
, op: 'update'
42+
, changes: ctx.ddata.processRawDataForRuntime([obj])
43+
});
44+
45+
// Last object! Return results
46+
if (i == statuses.length - 1) {
47+
fn(null, r);
48+
ctx.bus.emit('data-received');
49+
}
50+
}
51+
});
52+
};
3653
}
3754

3855
function last (fn) {
@@ -109,7 +126,10 @@ function storage (collection, ctx) {
109126
api.aggregate = require('./aggregate')({}, api);
110127
api.indexedFields = [
111128
'created_at'
112-
129+
130+
131+
132+
113133
, 'NSCLIENT_ID'
114134
];
115135
return api;

npm-shrinkwrap.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nightscout",
3-
"version": "14.0.5",
3+
"version": "14.0.6",
44
"description": "Nightscout acts as a web-based CGM (Continuous Glucose Montinor) to allow multiple caregivers to remotely view a patients glucose data in realtime.",
55
"license": "AGPL-3.0",
66
"author": "Nightscout Team",

swagger.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"info": {
99
"title": "Nightscout API",
1010
"description": "Own your DData with the Nightscout API",
11-
"version": "14.0.5",
11+
"version": "14.0.6",
1212
"license": {
1313
"name": "AGPL 3",
1414
"url": "https://www.gnu.org/licenses/agpl.txt"

swagger.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ servers:
44
info:
55
title: Nightscout API
66
description: Own your DData with the Nightscout API
7-
version: 14.0.5
7+
version: 14.0.6
88
license:
99
name: AGPL 3
1010
url: 'https://www.gnu.org/licenses/agpl.txt'

0 commit comments

Comments
 (0)