diff options
| -rw-r--r-- | lib/bucky.js | 10 | ||||
| -rw-r--r-- | lib/db/index.js | 12 | ||||
| -rw-r--r-- | lib/index.js | 2 |
3 files changed, 21 insertions, 3 deletions
diff --git a/lib/bucky.js b/lib/bucky.js index ef822c4..aed6494 100644 --- a/lib/bucky.js +++ b/lib/bucky.js @@ -37,7 +37,15 @@ var bucky = module.exports = { }) next() }) - }, + }, + ensureHootbox: function (req, res, next){ + db.getCommentsForThread(1, 50).then(function(hootbox){ + res.hootbox = hootbox.forEach(function(comment){ + comment.set("comment", comment.get("comment").toString() ) + }) + next() + }) + }, /* DETAILS */ diff --git a/lib/db/index.js b/lib/db/index.js index 8e72d34..2c8486b 100644 --- a/lib/db/index.js +++ b/lib/db/index.js @@ -74,8 +74,16 @@ db.getFileSizes = function(ids){ } /* COMMENTS */ -db.getCommentsForThread = function (id){ - return Comment.query("where", "thread", "=", id).fetchAll() +db.getCommentsForThread = function (id, limit, offset){ + return Comment.query(function(qb){ + qb.where("thread", "=", id).orderBy("id", "desc") + if (limit) { + qb = qb.limit(limit) + } + if (offset) { + qb = qb.offset(offset) + } + }).fetchAll() } db.getCommentCounts = function(ids){ return knex.column('thread').count('* as count').select().from('comments').where('thread', 'in', ids).groupBy('thread') diff --git a/lib/index.js b/lib/index.js index f987077..51a8e07 100644 --- a/lib/index.js +++ b/lib/index.js @@ -83,9 +83,11 @@ site.route = function(){ bucky.ensureCommentCountsForThreads, bucky.ensureFileCountsForThreads, bucky.ensureFileSizeForThreads, + bucky.ensureHootbox, function(req, res){ res.json({ threads: res.threads, + hootbox: res.hootbox, }) } ) |
