Commit bed73829 authored by 陈志良's avatar 陈志良

Merge branch 'remould_0727_topic_cache' into SANDBOX

Conflicts:
	app/service/forumThreadService.js
parents 65530044 31a1ed77
...@@ -579,9 +579,7 @@ router.get('/thread/:tid/get', function(req, res, next) { ...@@ -579,9 +579,7 @@ router.get('/thread/:tid/get', function(req, res, next) {
} }
var threads = []; var threads = [];
threads.push(thread); threads.push(thread);
var firstLoadLevelBegin = new Date();
util.loadLevel(req.session.user.ent_code, threads, function() { util.loadLevel(req.session.user.ent_code, threads, function() {
console.log("获取帖子相关用户的经验(一个OpenId拿一次)总耗时:"+Math.abs(new Date() - firstLoadLevelBegin));
if (threads && threads.length > 0) { if (threads && threads.length > 0) {
thread = threads[0]; thread = threads[0];
} }
...@@ -607,7 +605,6 @@ router.get('/thread/:tid/get', function(req, res, next) { ...@@ -607,7 +605,6 @@ router.get('/thread/:tid/get', function(req, res, next) {
// rs.data = thread; // rs.data = thread;
// res.json(_.assign(rs, returnCode.SUCCESS)); // res.json(_.assign(rs, returnCode.SUCCESS));
} else { } else {
var redisPraiseLogBegin = new Date();
redisPraiseLog.get(ent_code, user.getMobileUser(req), 'thread', function(error, docs) { redisPraiseLog.get(ent_code, user.getMobileUser(req), 'thread', function(error, docs) {
if (thread.toObject) { if (thread.toObject) {
thread = thread.toObject(); thread = thread.toObject();
...@@ -619,7 +616,6 @@ router.get('/thread/:tid/get', function(req, res, next) { ...@@ -619,7 +616,6 @@ router.get('/thread/:tid/get', function(req, res, next) {
break; break;
} }
}; };
console.log("redisPraiseLogTime:"+Math.abs(new Date() - redisPraiseLogBegin));
var rs = {}; var rs = {};
rs.data = thread; rs.data = thread;
res.json(_.assign(rs, returnCode.SUCCESS)); res.json(_.assign(rs, returnCode.SUCCESS));
...@@ -2279,7 +2275,97 @@ router.get('/thread/getThreadWithNotPopulateComment/hot', function(req, res, nex ...@@ -2279,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;
...@@ -2302,65 +2388,72 @@ router.get('/thread/:tid/get/subThreads/:type', function(req, res, next) { ...@@ -2302,65 +2388,72 @@ router.get('/thread/:tid/get/subThreads/:type', function(req, res, next) {
} }
if (tid) { if (tid) {
async.waterfall([ var key = 'pisns-forum-thread:' +ent_code+':'+ tid + ':subThreads:type='+type+'&pageNo='+pageNo+'&pageSize='+pageSize;
function(callback) { redis.get(key,function(err,value){
forumThreadService.getByConditionsSelectyField({_id:tid}, 'type', function(err, thread) { if (value) {
if (err) { res.json(_.assign(value, returnCode.SUCCESS));
console.error(err); } else {
callback(err, null); async.waterfall([
} else { function(callback) {
callback(null, thread); var getByConditionsSelectyFieldBegin = new Date();
forumThreadService.getByConditionsSelectyField({_id:tid}, 'type', function(err, thread) {
console.log("获取父帖子耗时:"+ Math.asb(new Date() - getByConditionsSelectyFieldBegin));
if (err) {
console.error(err);
callback(err, null);
} else {
callback(null, thread);
}
});
},
function(thread, callback) {
callback(null, thread, null);
},
function(thread, doc, callback) {
if (thread.type == 2) { //查询子列表
if (doc) {
conditions._id = {
$nin: doc.thread
};
}
var getThreadWithNotPopulateCommentBegin = new Date();
//获取子话题数据
forumThreadService.getThreadWithNotPopulateComment(conditions, pageNo, pageSize, sort, function(err, results) {
console.log("查询子帖子列表耗时:"+Math.asb(new Date() - getThreadWithNotPopulateCommentBegin));
if (err) {
console.error(err);
callback(err, null);
} else {
callback(null, results);
}
});
} else {
callback(null, null);
}
} }
}); ], function(err, results) {
},
function(thread, callback) {
forumUserThreadControlService.getUserThreadControlById(user.getMobileUser(req), function(err, doc) {
if (err) { if (err) {
console.error(err); console.error(err);
callback(err, null, null); res.json(returnCode.BUSY);
} else { } else {
if (doc) { if(results){
callback(null, thread, doc); var loadLevelBegin = new Date();
} else { util.loadLevel(ent_code, results.items, function() {
callback(null, thread, null); console.log("查询用户经验耗时:"+Math.asb(new Date() - loadLevelBegin));
var handleThreadListBegin = new Date();
handleThreadList(req, results, ent_code, function(result){
console.log("查询用户对帖子点赞耗时:"+Math.asb(new Date() - handleThreadListBegin));
redis.set(key, _.assign(result, returnCode.SUCCESS));
redis.expire(key, 2);
res.json(_.assign(result, returnCode.SUCCESS));
});
});
}else{
res.json(returnCode.SUCCESS);
} }
} }
}); });
},
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 { } else {
......
This source diff could not be displayed because it is too large. You can view the blob instead.
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