mirror of
https://github.com/bckelley/cgm-remote-monitor.git
synced 2026-08-24 03:14:12 -05:00
re-use entries in websocket
Address some of @jason.calabrese's feedback.
This commit is contained in:
+10
-2
@@ -4,12 +4,14 @@ function entries (name, storage) {
|
||||
function list (opts, fn) {
|
||||
with_collection(function (err, collection) {
|
||||
function find ( ) {
|
||||
var q = { };
|
||||
var q = opts && opts.find ? opts.find : { };
|
||||
return q;
|
||||
return this.find(q)
|
||||
;
|
||||
}
|
||||
|
||||
function sort ( ) {
|
||||
return {"date": -1};
|
||||
return this.sort({"date": -1});
|
||||
}
|
||||
|
||||
@@ -24,7 +26,13 @@ function entries (name, storage) {
|
||||
fn(err, entries);
|
||||
}
|
||||
|
||||
limit.call(sort.call(find.call(collection))).toArray(toArray);
|
||||
limit.call(collection
|
||||
.find(find( ))
|
||||
.sort(sort( )))
|
||||
// .limit(limit( ))
|
||||
.toArray(toArray)
|
||||
;
|
||||
// limit.call(sort.call(find.call(collection))).toArray(toArray);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
+8
-6
@@ -1,5 +1,5 @@
|
||||
|
||||
function websocket (env, server, store) {
|
||||
function websocket (env, server, entries) {
|
||||
"use strict";
|
||||
// CONSTANTS
|
||||
var ONE_HOUR = 3600000,
|
||||
@@ -102,10 +102,13 @@ function update() {
|
||||
|
||||
cgmData = [];
|
||||
var earliest_data = now - TWO_DAYS;
|
||||
store(function ( ) {
|
||||
var collection = store.collection(env.mongo_collection);
|
||||
// store(function ( ) {
|
||||
// });
|
||||
var q = { find: {"date": {"$gte": earliest_data}} };
|
||||
// var collection = store.collection(env.mongo_collection);
|
||||
|
||||
collection.find({"date": {"$gte": earliest_data}}).toArray(function(err, results) {
|
||||
// collection.find({"date": {"$gte": earliest_data}}).toArray(function(err, results) {
|
||||
entries.list(q, function (err, results) {
|
||||
results.forEach(function(element, index, array) {
|
||||
if (element) {
|
||||
var obj = {};
|
||||
@@ -118,8 +121,7 @@ function update() {
|
||||
});
|
||||
// all done, do loadData
|
||||
loadData( );
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
return update;
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ store(function ready ( ) {
|
||||
// setup socket io for data and message transmission
|
||||
///////////////////////////////////////////////////
|
||||
var websocket = require('./lib/websocket');
|
||||
var io = websocket(env, server, store);
|
||||
var io = websocket(env, server, entries);
|
||||
});
|
||||
|
||||
///////////////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user