Skip to content
This repository has been archived by the owner on Dec 2, 2020. It is now read-only.

Commit

Permalink
Minor tweak.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Apr 15, 2012
1 parent 76a7527 commit 4814549
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/cube/server/event.js
Expand Up @@ -57,8 +57,8 @@ exports.putter = function(db) {
// Events are indexed by time.
events.ensureIndex({"t": 1}, handle);

// Create a capped collection for metrics. Two indexes are required:
// one for computing, and the other for invalidating.
// Create a capped collection for metrics. Three indexes are required: one
// for finding metrics, one (_id) for updating, and one for invalidation.
db.createCollection(type + "_metrics", metric_options, function(error, metrics) {
handle(error);
metrics.ensureIndex({"i": 1, "_id.e": 1, "_id.l": 1, "_id.t": 1}, handle);
Expand Down
14 changes: 9 additions & 5 deletions lib/cube/server/metric.js
Expand Up @@ -102,10 +102,10 @@ exports.getter = function(db) {
// Immediately report back whatever we have. If any values are missing,
// merge them into contiguous intervals and asynchronously compute them.
function foundMetrics(error, cursor) {
if (error) throw error;
handle(error);
var time = start;
cursor.each(function(error, row) {
if (error) throw error;
handle(error);
if (row) {
info.stat("metrics_cached", name, step).add(1);
callback(row._id.t, row.v);
Expand Down Expand Up @@ -136,10 +136,10 @@ exports.getter = function(db) {
filter.t.$gte = start;
filter.t.$lt = stop;
type.events.find(filter, fields, event_options, function(error, cursor) {
if (error) throw error;
handle(error);
var time = start, values = [];
cursor.each(function(error, row) {
if (error) throw error;
handle(error);
if (row) {
var then = tier.floor(row.t);
if (time < then) {
Expand Down Expand Up @@ -168,7 +168,7 @@ exports.getter = function(db) {
},
i: false,
v: new Double(value)
}, function(error) { if (error) throw error; });
}, handle);
info.stat("metrics_computed", name, step).add(1);
} else {
info.stat("metrics_zeroed", name, step).add(1);
Expand Down Expand Up @@ -230,3 +230,7 @@ exports.getter = function(db) {
: function(time, value) { callback({time: time, value: value}); });
};
};

function handle(error) {
if (error) throw error;
}

0 comments on commit 4814549

Please sign in to comment.