Commit 585ec733 authored by strong's avatar strong

Merge branch 'remould_1214_api_optimize' into SANDBOX

parents c75e8d9d c76dbf7f
......@@ -17,6 +17,8 @@ router.get('/commentTips', function(req, res, next) {
if(err){
res.json(returnCode.UNCHECK_ERROR(err));
}else{
res.setHeader('Cache-Control', 'private, max-age=600'); // 私有缓存一个10分钟
res.setHeader('Expires', new Date(Date.now() + 600000).toUTCString());
res.json(_.assign({data:result}, returnCode.SUCCESS));
}
});
......
......@@ -37,6 +37,8 @@ router.get('/info/list/all', function(req, res, next) {
res.json(returnCode.BUSY);
} else {
rs.data = datas.items;
res.setHeader('Cache-Control', 'public, max-age=3600'); // 公共缓存一个小时
res.setHeader('Expires', new Date(Date.now() + 3600000).toUTCString());
res.json(_.assign(rs, returnCode.SUCCESS));
}
});
......@@ -66,18 +68,13 @@ router.get('/info/:fid/get', function(req, res, next) {
if (fid) {
var source = req.session.mobileForumUser.source;
httpService.createLog(req, source, fid, 2);
async.waterfall([
forumInfoService.updateInfoPvCount(fid, function(err, result) {
if (err) {
console.error(err);
}
});
async.parallel([
function(callback) {
//更新浏览数
forumInfoService.updateInfoPvCount(fid, function(err, result) {
if (err) {
callback(err, null);
} else {
callback(null, null);
}
});
},
function(data, callback) {
forumInfoService.getInfoById(fid, function(err, info) {
if (err) {
callback(err, null);
......@@ -86,25 +83,25 @@ router.get('/info/:fid/get', function(req, res, next) {
}
});
},
function(info, callback) {
function(callback) {
forumThreadService.getAllCountByFid({
info: fid
}, function(err, threadCount) {
if (err) {
callback(err, null, null);
callback(err, null);
} else {
callback(null, info, threadCount);
callback(null, threadCount);
}
});
}
], function(err, info, threadCount) {
], function(err, results) {
if (err) {
console.error(err);
res.json(returnCode.BUSY);
} else {
var rs = {};
rs.data = info;
rs.data.threadCount = threadCount;
rs.data = results[0];
rs.data.threadCount = results[1];
res.json(_.assign(rs, returnCode.SUCCESS));
}
});
......@@ -170,17 +167,18 @@ router.get('/info/:fid/threads', function(req, res, next) {
if (fid) {
async.waterfall([
function(callback) {
forumUserThreadControlService.getUserThreadControlById(user.getMobileUser(req), function(err, doc) {
if (err) {
callback(err, null);
} else {
if (doc) {
callback(null, doc);
} else {
callback(null, null);
}
}
});
callback(null, null);
// forumUserThreadControlService.getUserThreadControlById(user.getMobileUser(req), function(err, doc) {
// if (err) {
// callback(err, null);
// } else {
// if (doc) {
// callback(null, doc);
// } else {
// callback(null, null);
// }
// }
// });
}
], function(err, result) {
if (err) {
......@@ -667,6 +665,8 @@ router.get('/info/:fid/tags', function(req, res, next) {
console.error(err);
res.json(returnCode.BUSY);
} else {
res.setHeader('Cache-Control', 'public, max-age=3600'); // 公共缓存一个小时
res.setHeader('Expires', new Date(Date.now() + 3600000).toUTCString());
res.json(_.assign(results, returnCode.SUCCESS));
}
});
......
......@@ -72,6 +72,8 @@ router.get('/moderators/plates', function(req, res, next) {
if(result && result.infoIds){
items = result.infoIds;
}
res.setHeader('Cache-Control', 'public, max-age=3600'); // 公共缓存一个小时
res.setHeader('Expires', new Date(Date.now() + 3600000).toUTCString());
res.json(_.assign({items:items}, returnCode.SUCCESS));
});
});
......
......@@ -518,20 +518,16 @@ router.get('/thread/:tid/get', function(req, res, next) {
var tid = req.params.tid || null;
var ent_code = req.session.user.ent_code;
if (tid) {
async.waterfall([
async.waterfall([
function(callback) {
forumThreadService.updateThreadPvCount(tid, function(err, doc) {
forumThreadService.getThreadById(tid, function(err, thread) {
//文章类型 1、文章 2、话题 3、照片墙
if (err) {
callback(err, null);
} else {
callback(null, null);
callback(null, thread);
}
});
},
function(data, callback) {
forumThreadService.getThreadById(tid, function(err, thread) {
//文章类型 1、文章 2、话题 3、照片墙
var info_id = thread.info._id,
pid = thread.pid,
source = req.session.mobileForumUser.source;
......@@ -543,15 +539,12 @@ router.get('/thread/:tid/get', function(req, res, next) {
httpService.createLog(req, source, info_id, 3, 2, tid);
} else if (thread.type == 3 && thread.level == 1) {
httpService.createLog(req, source, info_id, 3, 3, tid);
}
}
});
forumThreadService.updateThreadPvCount(tid, function(err, doc) {
if (err) {
callback(err, null);
} else {
callback(null, thread);
}
console.error(err);
}
});
},
], function(err, thread) {
......
......@@ -4,6 +4,18 @@ var ForumComment = mongoose.model('ForumComment');
var forumUserService = require('./forumUserService');
var async = require('async');
var listCommentFields = {
from:1,
content:1,
level:1,
floor:1,
praise_count:1,
comment_count:1,
comments:1,
status:1
};
//创建评论
exports.createComment = function(entity, callback) {
var forum = new ForumComment(entity);
......@@ -125,7 +137,7 @@ exports.getAllComment = function(conditions, pageNo, pageSize, callback) {
var skip = (pageNo - 1) * pageSize;
var limit = count - skip > pageSize ? pageSize : (count - skip);
ForumComment.find(conditions).populate('from').populate('to').limit(limit).skip(skip).sort('-created').exec(function(err, docs) {
ForumComment.find(conditions,listCommentFields).populate('from','uid mid nickName icon exp').populate('to','uid mid nickName icon exp').limit(limit).skip(skip).sort('-created').exec(function(err, docs) {
if (err) {
console.error(err);
callback(err, null);
......
This diff is collapsed.
......@@ -21,7 +21,7 @@ module.exports = function(app, config) {
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(compress());
// app.use(compress());
app.use(cookieParser());
app.use(methodOverride());
app.use(multiparty());
......
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