Commit 31a1ed77 authored by 陈志良's avatar 陈志良

缓存子帖查询API

parent d23d39fc
...@@ -2275,7 +2275,97 @@ router.get('/thread/getThreadWithNotPopulateComment/hot', function(req, res, nex ...@@ -2275,7 +2275,97 @@ router.get('/thread/getThreadWithNotPopulateComment/hot', function(req, res, nex
}); });
//获取话题下子文章 //获取话题下子文章
// router.get('/thread/:tid/get/subThreads/:type', function(req, res, next) {
// var tid = req.params.tid || null;
// var type = req.params.type || null;
// var pageNo = req.query.pageNo || 1;
// var pageSize = req.query.pageSize || 10;
// var ent_code = req.session.user.ent_code;
// var rs = {};
// var conditions = {
// ent_code: ent_code,
// pid: tid,
// // type: 2,
// status: 1
// };
// var sort = null; //排序条件
// if(type == 1){ //最新
// sort = '-created';
// }else if(type == 2){ //最热
// sort = '-praise_count -comment_count -created';
// }
// if (tid) {
// async.waterfall([
// function(callback) {
// forumThreadService.getByConditionsSelectyField({_id:tid}, 'type', function(err, thread) {
// if (err) {
// console.error(err);
// callback(err, null);
// } else {
// callback(null, thread);
// }
// });
// },
// function(thread, callback) {
// forumUserThreadControlService.getUserThreadControlById(user.getMobileUser(req), function(err, doc) {
// if (err) {
// console.error(err);
// callback(err, null, null);
// } else {
// if (doc) {
// callback(null, thread, doc);
// } else {
// callback(null, thread, null);
// }
// }
// });
// },
// function(thread, doc, callback) {
// if (thread.type == 2) { //查询子列表
// if (doc) {
// conditions._id = {
// $nin: doc.thread
// };
// }
// //获取子话题数据
// forumThreadService.getThreadWithNotPopulateComment(conditions, pageNo, pageSize, sort, function(err, results) {
// if (err) {
// console.error(err);
// callback(err, null);
// } else {
// callback(null, results);
// }
// });
// } else {
// callback(null, null);
// }
// }
// ], function(err, results) {
// if (err) {
// console.error(err);
// res.json(returnCode.BUSY);
// } else {
// if(results){
// util.loadLevel(ent_code, results.items, function() {
// handleThreadList(req, results, ent_code, function(result){
// res.json(_.assign(result, returnCode.SUCCESS));
// });
// });
// }else{
// res.json(returnCode.SUCCESS);
// }
// }
// });
// } else {
// res.json(returnCode.WRONG_PARAM);
// }
// });
//(缓存)获取话题下子文章
router.get('/thread/:tid/get/subThreads/:type', function(req, res, next) { router.get('/thread/:tid/get/subThreads/:type', function(req, res, next) {
var tid = req.params.tid || null; var tid = req.params.tid || null;
var type = req.params.type || null; var type = req.params.type || null;
...@@ -2298,6 +2388,11 @@ router.get('/thread/:tid/get/subThreads/:type', function(req, res, next) { ...@@ -2298,6 +2388,11 @@ router.get('/thread/:tid/get/subThreads/:type', function(req, res, next) {
} }
if (tid) { if (tid) {
var key = 'pisns-forum-thread:' +ent_code+':'+ tid + ':subThreads:type='+type+'&pageNo='+pageNo+'&pageSize='+pageSize;
redis.get(key,function(err,value){
if (value) {
res.json(_.assign(value, returnCode.SUCCESS));
} else {
async.waterfall([ async.waterfall([
function(callback) { function(callback) {
var getByConditionsSelectyFieldBegin = new Date(); var getByConditionsSelectyFieldBegin = new Date();
...@@ -2313,18 +2408,6 @@ router.get('/thread/:tid/get/subThreads/:type', function(req, res, next) { ...@@ -2313,18 +2408,6 @@ router.get('/thread/:tid/get/subThreads/:type', function(req, res, next) {
}, },
function(thread, callback) { function(thread, callback) {
callback(null, thread, null); callback(null, thread, null);
// forumUserThreadControlService.getUserThreadControlById(user.getMobileUser(req), function(err, doc) {
// if (err) {
// console.error(err);
// callback(err, null, null);
// } else {
// if (doc) {
// callback(null, thread, doc);
// } else {
// callback(null, thread, null);
// }
// }
// });
}, },
function(thread, doc, callback) { function(thread, doc, callback) {
if (thread.type == 2) { //查询子列表 if (thread.type == 2) { //查询子列表
...@@ -2360,6 +2443,8 @@ router.get('/thread/:tid/get/subThreads/:type', function(req, res, next) { ...@@ -2360,6 +2443,8 @@ router.get('/thread/:tid/get/subThreads/:type', function(req, res, next) {
var handleThreadListBegin = new Date(); var handleThreadListBegin = new Date();
handleThreadList(req, results, ent_code, function(result){ handleThreadList(req, results, ent_code, function(result){
console.log("查询用户对帖子点赞耗时:"+Math.asb(new Date() - handleThreadListBegin)); console.log("查询用户对帖子点赞耗时:"+Math.asb(new Date() - handleThreadListBegin));
redis.set(key, _.assign(result, returnCode.SUCCESS));
redis.expire(key, 2);
res.json(_.assign(result, returnCode.SUCCESS)); res.json(_.assign(result, returnCode.SUCCESS));
}); });
}); });
...@@ -2368,6 +2453,9 @@ router.get('/thread/:tid/get/subThreads/:type', function(req, res, next) { ...@@ -2368,6 +2453,9 @@ router.get('/thread/:tid/get/subThreads/:type', function(req, res, next) {
} }
} }
}); });
}
});
} else { } else {
res.json(returnCode.WRONG_PARAM); res.json(returnCode.WRONG_PARAM);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment