From efd58a5c27bd17d4ae8d4bb4a27f36c213d83d41 Mon Sep 17 00:00:00 2001 From: Philip Roberts Date: Tue, 10 Apr 2012 23:16:57 +0100 Subject: [PATCH] Fixes #12 - incorrect sort order during a build. - Spotting that MongoHub was also listing the current build in a random order, I fixed this issue by just forcing a sort order. Performance doesn't seem like it's the most important thing for an app like this. - I wonder if the issue is related to natural vs insertion sort order, see: http://www.mongodb.org/display/DOCS/Sorting+and+Natural+Order --- lib/jobs.js | 8 ++++++-- src/jobs.coffee | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/jobs.js b/lib/jobs.js index b57f2aa..eb0db8c 100644 --- a/lib/jobs.js +++ b/lib/jobs.js @@ -131,11 +131,15 @@ getJobs = function(filter, next) { return db.collection('jobs', function(error, collection) { if (filter != null) { - return collection.find(filter).toArray(function(error, results) { + return collection.find(filter).sort({ + addedTime: 1 + }).toArray(function(error, results) { return next(results); }); } else { - return collection.find().toArray(function(error, results) { + return collection.find().sort({ + addedTime: 1 + }).toArray(function(error, results) { return next(results); }); } diff --git a/src/jobs.coffee b/src/jobs.coffee index 6112ea8..abd1b5f 100644 --- a/src/jobs.coffee +++ b/src/jobs.coffee @@ -91,8 +91,8 @@ jobs = module.exports = getJobs = (filter, next)-> db.collection 'jobs', (error, collection) -> if filter? - collection.find(filter).toArray (error, results) -> + collection.find(filter).sort({addedTime: 1}).toArray (error, results) -> next results else - collection.find().toArray (error, results) -> + collection.find().sort({addedTime: 1}).toArray (error, results) -> next results