Commit 2678facf authored by strong's avatar strong

Merge branch 'remould_1120_spreadchain' into SANDBOX

parents 5b13b98c 52fe4c82
...@@ -1078,6 +1078,102 @@ router.get('/thread/:tid/spreadchain', function(req, res, next) { ...@@ -1078,6 +1078,102 @@ router.get('/thread/:tid/spreadchain', function(req, res, next) {
}); });
//udpate by Car 20151208 使用redis优化传播链图
router.get('/thread/:tid/spreadchainByRedis', function(req, res, next) {
var tid = req.params.tid || null,
ent_code = req.session.user.ent_code;
var openIds = [];
then.parallel([
function(cont) {
ForumThread.findOne({
_id: tid,
ent_code: ent_code
}).populate('from').exec(function(err, doc) {
cont(err, doc);
});
},
function(cont) {
ForumPVLog.find({
thread: tid,
ent_code: ent_code
}).sort('source created').populate('user source').exec(function(err, docs) {
cont(err, docs);
});
}
]).then(function(cont, results) {
var thread = results[0],
pvs = results[1];
var data = {
openId: thread.from.uid,
name: thread.from.nickName,
//nickName: thread.from.displayName,
nickName: thread.from.nickName,
children: [] ,
id : 'ROOT'
}
//获取一级传播
for (var i = 0; i < pvs.length; i += 1) {
var pv = pvs[i];
if (!pv.source) {
var flag = false;
for (var j = 0; j < data.children.length; j += 1) {
var c = data.children[j];
if (c.openId === pv.open_id) {
flag = true;
break;
}
}
if (!flag && pv.open_id !== data.openId && !checkOpenIds(openIds, pv.open_id)) {
data.children.push({
openId: pv.open_id,
nickName: pv.user.displayName || '未知',
name: pv.user.nickName || '未知',
id : pv._id
});
openIds.push(pv.open_id);
}
}
}
//获取非一级传播
var new_pvs = [];
for (var i = 0; i < pvs.length; i += 1) {
if (pvs[i].source && pvs[i].source.uid !== data.openId && pvs[i].open_id !== data.openId) {
new_pvs.push(pvs[i]);
}
}
pvs = new_pvs;
//递归其他传播
var thenTask = [];
_.forEach(data.children, function(c) {
thenTask.push(function(cb) {
getSubSpreadPaths(openIds, c, pvs, cb);
});
})
then.parallel(thenTask).then(function(cont, childrens) {
data.children = childrens;
//put data into redis
var key = tid + "_spreadchain"
console.log("spreadchain data=" + data);
redis.set(key,JSON.stringify(data));
redis.expire(key,60);
var rs = {
data: key
}
openIds = [];
res.json(_.assign(rs, returnCode.SUCCESS));
});
}).fail(function(cont, err) {
console.error(err);
res.json(returnCode.BUSY);
});
});
// 导出文章评论内容 // 导出文章评论内容
router.get('/thread/:tid/exportComments', function(req, res, next) { router.get('/thread/:tid/exportComments', function(req, res, next) {
var tid = req.params.tid || null, var tid = req.params.tid || null,
......
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