Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pisns-forum-api
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
scrmGroup
pisns-forum-api
Commits
fd749970
Commit
fd749970
authored
Mar 10, 2016
by
陈家荣
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
帖子修改排序号后及时在移动端更新效果
parent
18abca5d
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
408 additions
and
264 deletions
+408
-264
forumThread.js
app/controllers/admin/forumThread.js
+37
-26
forumThread.js
app/controllers/mobile/forumThread.js
+13
-13
forumThreadService.js
app/service/forumThreadService.js
+303
-174
redisThreadList.js
app/utils/redisThreadList.js
+55
-51
No files found.
app/controllers/admin/forumThread.js
View file @
fd749970
...
...
@@ -322,7 +322,7 @@ router.post('/thread/:tid/:fid/unTop', function(req, res, next) {
}
});
//文章
推荐
//文章
加精
router
.
post
(
'/thread/:tid/:fid/recommend'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
,
fid
=
req
.
params
.
fid
,
...
...
@@ -364,7 +364,7 @@ router.post('/thread/:tid/:fid/recommend', function(req, res, next) {
}
});
//文章取消
推荐
//文章取消
加精
router
.
post
(
'/thread/:tid/:fid/unRecommend'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
;
//文章ID
var
fid
=
req
.
params
.
fid
;
//板块ID
...
...
@@ -555,11 +555,17 @@ router.get('/threads/list', function(req, res, next) {
//直接修改序号
function
updateThreadTopIdx
(
id
,
idx
,
callback
){
ForumThread
.
update
(
{
_id
:
id
},
{
top_order_idx
:
idx
},
null
,
function
(
err
,
result
){
// ForumThread.update({_id:id},{ top_order_idx: idx },
// null,
// function(err,result){
// if(err){
// console.error(err);
// callback(err,null);
// }else{
// callback(null,true);
// }
// });
forumThreadService
.
updateThread
({
_id
:
id
},
{
top_order_idx
:
idx
},
function
(
err
,
doc
)
{
if
(
err
){
console
.
error
(
err
);
callback
(
err
,
null
);
...
...
@@ -569,11 +575,16 @@ function updateThreadTopIdx(id,idx,callback){
});
}
function
updateThreadNewRecommendIdx
(
id
,
idx
,
callback
){
ForumThread
.
update
(
{
_id
:
id
},
{
new_recommend_order_idx
:
idx
},
null
,
function
(
err
,
result
){
// ForumThread.update({_id:id},{ new_recommend_order_idx: idx },null, function(err,result){
// if(err){
// console.error(err);
// callback(err,null);
// }else{
// callback(null,true);
// }
// });
forumThreadService
.
updateThread
({
_id
:
id
},
{
new_recommend_order_idx
:
idx
},
function
(
err
,
doc
)
{
if
(
err
){
console
.
error
(
err
);
callback
(
err
,
null
);
...
...
app/controllers/mobile/forumThread.js
View file @
fd749970
...
...
@@ -666,13 +666,16 @@ router.post('/thread/:tid/update', function(req, res, next) {
router
.
post
(
'/thread/:tid/delete'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
;
if
(
tid
)
{
forumThreadService
.
deleteThreadById
(
tid
,
function
(
err
,
thread
)
{
if
(
err
)
{
//注销此方法
// forumThreadService.deleteThreadById(tid, function(err, thread) {
// if (err) {
// res.json(returnCode.BUSY);
// } else {
// res.json(returnCode.SUCCESS);
// }
// });
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
...
...
@@ -1756,8 +1759,6 @@ router.get('/thread/getThreadWithEssence', function(req, res, next) {
var
infoId
=
req
.
query
.
infoId
||
null
;
var
ent_code
=
req
.
session
.
user
.
ent_code
;
var
skip
=
(
pageNo
-
1
)
*
pageSize
;
var
redis_type
=
'_thread_essence'
;
var
sort
=
{
new_recommend
:
-
1
,
new_recommend_order_idx
:
-
1
,
...
...
@@ -1786,7 +1787,6 @@ router.get('/thread/getThreadWithEssence', function(req, res, next) {
}]
};
if
((
pageNo
*
pageSize
)
>
redisThreadList
.
getThreadRedisCount
()
||
infoId
){
if
(
infoId
){
conditions
.
info
=
infoId
;
...
...
@@ -1805,10 +1805,10 @@ router.get('/thread/getThreadWithEssence', function(req, res, next) {
});
}
else
{
//更新推荐列表redis
redisThreadList
.
get
(
ent_code
,
""
,
redis_type
,
function
(
error
,
docs
)
{
redisThreadList
.
get
(
ent_code
,
function
(
error
,
docs
)
{
var
results
=
JSON
.
parse
(
docs
);
if
(
results
.
items
==
null
||
results
.
items
.
length
<=
0
){
//如果不存在,继续重新获取
redisThreadList
.
getRedisEsenceThreads
(
ent_code
,
""
,
redis_type
,
function
(
error
,
docs
){
redisThreadList
.
getRedisEsenceThreads
(
ent_code
,
function
(
error
,
docs
){
if
(
error
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
...
...
@@ -1945,7 +1945,7 @@ router.get('/thread/:tid/get/subThreads/:type', function(req, res, next) {
if
(
type
==
1
){
//最新
sort
=
'-created'
;
}
else
if
(
type
==
2
){
//最热
sort
=
'-praise_count -comment_count'
;
}
if
(
tid
)
{
...
...
app/service/forumThreadService.js
View file @
fd749970
...
...
@@ -10,6 +10,8 @@ var forumCommentService = require('./forumCommentService');
var
async
=
require
(
'async'
);
var
then
=
require
(
'thenjs'
);
var
redisThreadList
=
require
(
'../utils/redisThreadList'
);
var
listThreadFields
=
{
content
:
1
,
...
...
@@ -53,8 +55,6 @@ var singleThreadFields = {
};
var
subThreadFields
=
{
from
:
1
};
...
...
@@ -89,14 +89,33 @@ function handleContent(content) {
return
content
.
trim
();
}
function
findOneAndUpdate
(
id
,
entity
,
callback
)
{
ForumThread
.
findOneAndUpdate
(
id
,
entity
,
function
(
err
,
doc
)
{
//更新帖子方法, afterOperation为更新之后做的操作的条件
function
findOneAndUpdate
(
condition
,
entity
,
afterOperation
,
callback
)
{
ForumThread
.
findOneAndUpdate
(
condition
,
entity
,
function
(
err
,
doc
)
{
callback
(
err
,
doc
);
if
(
afterOperation
==
'updateRedisRecommentThreads'
&&
doc
&&
doc
.
new_recommend
==
1
){
//刷新缓存
redisThreadList
.
updateRedisEsenceThreads
(
doc
.
ent_code
);
}
});
};
//更新帖子方法, afterOperation为更新之后做的操作的条件
function
update
(
condition
,
entity
,
operation
,
afterOperation
,
callback
)
{
ForumThread
.
update
(
condition
,
entity
,
operation
,
function
(
err
,
doc
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
null
);
if
(
afterOperation
==
'updateRedisRecommentThreads'
&&
doc
&&
doc
.
new_recommend
==
1
){
//刷新缓存
redisThreadList
.
updateRedisEsenceThreads
(
doc
.
ent_code
);
}
}
});
};
//分页查询话题列表
exports
.
findThread
=
function
(
pageNo
,
pageSize
,
q
,
sort
,
callback
)
{
then
(
function
(
cont
)
{
...
...
@@ -550,17 +569,31 @@ exports.updateThreadById = function(tid, entity, callback) {
entity
.
share
=
''
;
}
if
(
entity
.
share
)
{
ForumThread
.
update
({
_id
:
tid
},
entity
,
null
,
function
(
err
,
result
)
{
// ForumThread.update({
// _id: tid
// }, entity, null, function(err, result) {
// if (err) {
// console.error(err);
// callback(err, null);
// } else {
// ForumShare.update({
// _id: shareEntity._id
// }, shareEntity, null, function(err, se) {
// if (err) {
// console.error(err);
// callback(err, null);
// } else {
// callback(null, entity);
// }
// });
// }
// });
findOneAndUpdate
({
_id
:
tid
},
entity
,
'updateRedisRecommentThreads'
,
function
(
err
,
result
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
ForumShare
.
update
({
_id
:
shareEntity
.
_id
},
shareEntity
,
null
,
function
(
err
,
se
)
{
ForumShare
.
update
({
_id
:
shareEntity
.
_id
},
shareEntity
,
null
,
function
(
err
,
se
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
...
...
@@ -568,14 +601,11 @@ exports.updateThreadById = function(tid, entity, callback) {
callback
(
null
,
entity
);
}
});
}
});
}
else
{
if
(
shareEntity
&&
(
shareEntity
.
title
||
shareEntity
.
description
||
shareEntity
.
icon
))
{
shareEntity
.
ent_code
=
entity
.
ent_code
;
var
forumShare
=
new
ForumShare
(
shareEntity
);
forumShare
.
save
(
function
(
err
,
forumShare
)
{
entity
.
share
=
forumShare
.
_id
;
...
...
@@ -587,15 +617,29 @@ exports.updateThreadById = function(tid, entity, callback) {
callback
(
err
,
null
);
}
else
{
callback
(
null
,
entity
);
}
});
});
}
else
{
delete
entity
.
share
;
ForumThread
.
update
({
_id
:
tid
},
entity
,
null
,
function
(
err
,
result
)
{
// ForumThread.update({
// _id: tid
// }, entity, null, function(err, result) {
// if (err) {
// console.error(err);
// callback(err, null);
// } else {
// callback(null, entity);
// }
// });
findOneAndUpdate
({
_id
:
tid
},
entity
,
'updateRedisRecommentThreads'
,
function
(
err
,
result
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
ForumShare
.
update
({
_id
:
shareEntity
.
_id
},
shareEntity
,
null
,
function
(
err
,
se
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
...
...
@@ -605,16 +649,27 @@ exports.updateThreadById = function(tid, entity, callback) {
}
});
}
});
}
}
};
//逻辑删除文章
exports
.
logicDeleteThreadById
=
function
(
tid
,
callback
)
{
ForumThread
.
update
({
_id
:
mongoose
.
Types
.
ObjectId
(
tid
)
},
{
status
:
3
},
null
,
function
(
err
,
result
)
{
// ForumThread.update({
// _id: mongoose.Types.ObjectId(tid)
// }, {
// status : 3
// }, null, function(err, result) {
// if (err) {
// console.error(err);
// callback(err, false);
// } else {
// callback(null, true);
// }
// });
findOneAndUpdate
({
_id
:
mongoose
.
Types
.
ObjectId
(
tid
)},
{
status
:
3
},
'updateRedisRecommentThreads'
,
function
(
err
,
result
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
false
);
...
...
@@ -625,11 +680,9 @@ exports.logicDeleteThreadById = function(tid, callback) {
};
//根据ID
更新
文章
//根据ID
删除
文章
exports
.
deleteThreadById
=
function
(
tid
,
callback
)
{
ForumThread
.
remove
({
_id
:
tid
},
function
(
err
,
result
)
{
ForumThread
.
remove
({
_id
:
tid
},
function
(
err
,
result
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
...
...
@@ -923,41 +976,45 @@ exports.getAllThreadByFid = function(conditions, pageNo, pageSize, sort, callbac
//根据板块ID更新板块下的top为0,并把当前文章的top设为1(置顶)
exports
.
updateTopByThreadId
=
function
(
infoId
,
threadId
,
callback
)
{
// ForumThread.update({info:infoId}, {top:0},{multi:true}, function(err, doc) {
// if(err){
// callback(err,null);
// }else{
// ForumThread.findOneAndUpdate({_id:threadId}, {top:1}, function(err, doc) {
// if(err){
// callback(err,null);
// }else{
// callback(null,null);
// }
// });
// ForumThread.findOneAndUpdate({
// _id: threadId
// }, {
// top: 1,
// topTime: new Date()
// }, function(err, doc) {
// if (err) {
// callback(err, null);
// } else {
// callback(null, null);
// }
// });
ForumThread
.
findOneAndUpdate
({
_id
:
threadId
},
{
top
:
1
,
topTime
:
new
Date
()
},
function
(
err
,
doc
)
{
findOneAndUpdate
({
_id
:
threadId
},
{
top
:
1
,
topTime
:
new
Date
()},
'updateRedisRecommentThreads'
,
function
(
err
,
doc
){
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
null
);
callback
(
null
,
doc
);
}
});
};
//根据板块ID更新板块下的top为0,并把当前文章的top设为1(置顶)
exports
.
updateUnTopByThreadId
=
function
(
infoId
,
threadId
,
callback
)
{
ForumThread
.
findOneAndUpdate
({
_id
:
threadId
},
{
top
:
0
,
topTime
:
null
},
function
(
err
,
doc
)
{
// ForumThread.findOneAndUpdate({
// _id: threadId
// }, {
// top: 0,
// topTime: null
// }, function(err, doc) {
// if (err) {
// callback(err, null);
// } else {
// callback(null, null);
// }
// });
findOneAndUpdate
({
_id
:
threadId
},
{
top
:
0
,
topTime
:
null
},
'updateRedisRecommentThreads'
,
function
(
err
,
doc
)
{
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
...
...
@@ -965,23 +1022,31 @@ exports.updateUnTopByThreadId = function(infoId, threadId, callback) {
}
});
};
//根据文章ID更新文章为
推荐
//根据文章ID更新文章为
加精
exports
.
updateRecommendByThreadId
=
function
(
threadId
,
callback
)
{
ForumThread
.
findOneAndUpdate
({
_id
:
threadId
},
{
recommend
:
1
},
function
(
err
,
doc
)
{
// ForumThread.findOneAndUpdate({
// _id: threadId
// }, {
// recommend: 1
// }, function(err, doc) {
// callback(err,doc);
// });
findOneAndUpdate
({
_id
:
threadId
},
{
recommend
:
1
},
'updateRedisRecommentThreads'
,
function
(
err
,
doc
)
{
callback
(
err
,
doc
);
});
};
//根据文章ID更新文章为不
推荐
//根据文章ID更新文章为不
加精
exports
.
updateUnRecommendByThreadId
=
function
(
threadId
,
callback
)
{
ForumThread
.
findOneAndUpdate
({
_id
:
threadId
},
{
recommend
:
0
},
function
(
err
,
doc
)
{
// ForumThread.findOneAndUpdate({
// _id: threadId
// }, {
// recommend: 0
// }, function(err, doc) {
// callback(err,null);
// });
findOneAndUpdate
({
_id
:
threadId
},
{
recommend
:
0
},
'updateRedisRecommentThreads'
,
function
(
err
,
doc
)
{
callback
(
err
,
null
);
});
};
...
...
@@ -993,12 +1058,20 @@ exports.updateTagTop = function(tid,tag_top,callback){
}
else
{
time
=
null
;
}
ForumThread
.
findOneAndUpdate
({
_id
:
tid
},
{
tag_top
:
tag_top
,
tag_topTime
:
time
},
function
(
err
,
doc
)
{
// ForumThread.findOneAndUpdate({
// _id: tid
// }, {
// tag_top: tag_top,
// tag_topTime: time
// }, function(err, doc) {
// if (err) {
// callback(err, null);
// } else {
// callback(null, doc);
// }
// });
findOneAndUpdate
({
_id
:
tid
},
{
tag_top
:
tag_top
,
tag_topTime
:
time
},
'updateRedisRecommentThreads'
,
function
(
err
,
doc
)
{
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
...
...
@@ -1009,17 +1082,27 @@ exports.updateTagTop = function(tid,tag_top,callback){
//更新文章点赞数
exports
.
updateThreadRaiseCount
=
function
(
threadId
,
callback
)
{
ForumThread
.
update
({
_id
:
threadId
},
{
$inc
:
{
praise_count
:
1
}
},
{
w
:
1
,
safe
:
true
},
function
(
err
,
result
)
{
// ForumThread.update({
// _id: threadId
// }, {
// $inc: {
// praise_count: 1
// }
// }, {
// w: 1,
// safe: true
// },
// function(err, result) {
// if (err) {
// console.error(err);
// callback(err, null);
// } else {
// callback(null, null);
// }
// });
update
({
_id
:
threadId
},
{
$inc
:
{
praise_count
:
1
}},
{
w
:
1
,
safe
:
true
},
'updateRedisRecommentThreads'
,
function
(
err
,
result
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
...
...
@@ -1031,17 +1114,26 @@ exports.updateThreadRaiseCount = function(threadId, callback) {
//减少文章点赞数
exports
.
updateThreadRaiseCountDec
=
function
(
threadId
,
callback
)
{
ForumThread
.
update
({
_id
:
threadId
},
{
$inc
:
{
praise_count
:
-
1
}
},
{
w
:
1
,
safe
:
true
},
function
(
err
,
result
)
{
// ForumThread.update({
// _id: threadId
// }, {
// $inc: {
// praise_count: -1
// }
// }, {
// w: 1,
// safe: true
// },
// function(err, result) {
// if (err) {
// console.error(err);
// callback(err, null);
// } else {
// callback(null, null);
// }
// });
update
({
_id
:
threadId
},
{
$inc
:
{
praise_count
:
-
1
}},
{
w
:
1
,
safe
:
true
},
'updateRedisRecommentThreads'
,
function
(
err
,
result
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
...
...
@@ -1053,17 +1145,26 @@ exports.updateThreadRaiseCountDec = function(threadId, callback) {
//更新文章分享数
exports
.
updateThreadShareCount
=
function
(
threadId
,
callback
)
{
ForumThread
.
update
({
_id
:
threadId
},
{
$inc
:
{
share_count
:
1
}
},
{
w
:
1
,
safe
:
true
},
function
(
err
,
result
)
{
// ForumThread.update({
// _id: threadId
// }, {
// $inc: {
// share_count: 1
// }
// }, {
// w: 1,
// safe: true
// },
// function(err, result) {
// if (err) {
// console.error(err);
// callback(err, null);
// } else {
// callback(null, null);
// }
// });
update
({
_id
:
threadId
},
{
$inc
:
{
share_count
:
1
}},
{
w
:
1
,
safe
:
true
},
null
,
function
(
err
,
result
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
...
...
@@ -1075,17 +1176,26 @@ exports.updateThreadShareCount = function(threadId, callback) {
//更新文章评论数
exports
.
updateThreadCommentCountInc
=
function
(
threadId
,
callback
)
{
ForumThread
.
update
({
_id
:
threadId
},
{
$inc
:
{
comment_count
:
1
}
},
{
w
:
1
,
safe
:
true
},
function
(
err
,
result
)
{
// ForumThread.update({
// _id: threadId
// }, {
// $inc: {
// comment_count: 1
// }
// }, {
// w: 1,
// safe: true
// },
// function(err, result) {
// if (err) {
// console.error(err);
// callback(err, null);
// } else {
// callback(null, null);
// }
// });
update
({
_id
:
threadId
},
{
$inc
:
{
comment_count
:
1
}},
{
w
:
1
,
safe
:
true
},
'updateRedisRecommentThreads'
,
function
(
err
,
result
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
...
...
@@ -1093,21 +1203,31 @@ exports.updateThreadCommentCountInc = function(threadId, callback) {
callback
(
null
,
null
);
}
});
};
//更新文章评论数
exports
.
updateThreadCommentCount
=
function
(
threadId
,
callback
)
{
ForumThread
.
update
({
_id
:
threadId
},
{
$inc
:
{
comment_count
:
-
1
}
},
{
w
:
1
,
safe
:
true
},
function
(
err
,
result
)
{
// ForumThread.update({
// _id: threadId
// }, {
// $inc: {
// comment_count: -1
// }
// }, {
// w: 1,
// safe: true
// },
// function(err, result) {
// if (err) {
// console.error(err);
// callback(err, null);
// } else {
// callback(null, null);
// }
// });
update
({
_id
:
threadId
},
{
$inc
:
{
comment_count
:
-
1
}},
{
w
:
1
,
safe
:
true
},
'updateRedisRecommentThreads'
,
function
(
err
,
result
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
...
...
@@ -1119,17 +1239,26 @@ exports.updateThreadCommentCount = function(threadId, callback) {
//更新文章浏览数
exports
.
updateThreadPvCount
=
function
(
threadId
,
callback
)
{
ForumThread
.
update
({
_id
:
threadId
},
{
$inc
:
{
pv_count
:
1
}
},
{
w
:
1
,
safe
:
true
},
function
(
err
,
result
)
{
// ForumThread.update({
// _id: threadId
// }, {
// $inc: {
// pv_count: 1
// }
// }, {
// w: 1,
// safe: true
// },
// function(err, result) {
// if (err) {
// console.error(err);
// callback(err, null);
// } else {
// callback(null, null);
// }
// });
update
({
_id
:
threadId
},
{
$inc
:
{
pv_count
:
1
}},
{
w
:
1
,
safe
:
true
},
'updateRedisRecommentThreads'
,
function
(
err
,
result
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
...
...
@@ -1239,7 +1368,7 @@ exports.getAllThreadByFidAndMid = function(mid, conditions, pageNo, pageSize, so
//更新文章
exports
.
updateThread
=
function
(
condition
,
entity
,
callback
)
{
ForumThread
.
findOneAndUpdate
(
condition
,
entity
,
function
(
err
,
doc
){
findOneAndUpdate
(
condition
,
entity
,
'updateRedisRecommentThreads'
,
function
(
err
,
doc
){
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
...
...
app/utils/redisThreadList.js
View file @
fd749970
'use strict'
;
var
redis
=
global
.
redis
;
var
expire
=
60
*
1
0
;
var
expire
=
60
*
3
0
;
//缓存数量
var
ThreadRedisCount
=
50
;
...
...
@@ -12,6 +12,10 @@ var forumThreadService=require('../service/forumThreadService');
var
redisPraiseLog
=
require
(
'./redisPraiseLog'
);
var
util
=
require
(
'./util'
);
var
RefreshFlag
=
true
;
var
tyhread_redis_salt
=
'_tyhread_redis_salt'
;
var
sort
=
{
new_recommend
:
-
1
,
new_recommend_order_idx
:
-
1
,
...
...
@@ -25,13 +29,13 @@ var sort = {
created
:
-
1
};
function
getKey
(
ent_code
,
keyID
,
type
){
var
key
=
ent_code
+
keyID
+
type
;
function
getKey
(
ent_code
,
salt
){
var
key
=
ent_code
+
salt
;
return
key
;
}
function
setToRedis
(
ent_code
,
keyID
,
type
,
value
){
var
key
=
getKey
(
ent_code
,
keyID
,
type
);
function
setToRedis
(
ent_code
,
salt
,
value
){
var
key
=
getKey
(
ent_code
,
salt
);
if
(
!
redis
){
console
.
log
(
'redis error'
);
return
'error'
...
...
@@ -42,8 +46,37 @@ function setToRedis(ent_code,keyID,type,value){
});
}
exports
.
get
=
function
(
ent_code
,
keyID
,
type
,
callback
){
var
key
=
getKey
(
ent_code
,
keyID
,
type
);
function
getEsenceThreads
(
ent_code
,
salt
,
callback
){
var
today
=
new
Date
();
var
conditions
=
{
ent_code
:
ent_code
,
level
:
1
,
status
:
1
,
new_recommend
:
1
,
$or
:
[{
isEvent
:
0
},
{
isEvent
:
null
},
{
isEvent
:
1
,
'event.eventStartTime'
:
{
$lte
:
today
}
}]
};
forumThreadService
.
getThreadWithNotPopulateComment
(
conditions
,
1
,
ThreadRedisCount
,
sort
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
);
}
else
{
util
.
loadLevel
(
ent_code
,
results
.
items
,
function
()
{
setToRedis
(
ent_code
,
salt
,
JSON
.
stringify
(
results
));
callback
(
null
);
});
}
});
};
exports
.
get
=
function
(
ent_code
,
callback
){
var
key
=
getKey
(
ent_code
,
tyhread_redis_salt
);
if
(
!
redis
){
console
.
log
(
'redis error'
);
return
callback
&&
callback
(
'error'
);
...
...
@@ -51,7 +84,7 @@ exports.get=function(ent_code,keyID,type,callback){
redis
.
get
(
key
,
function
(
error
,
res
){
if
(
!
res
){
//不存在,先获取再返回
getEsenceThreads
(
ent_code
,
keyID
,
type
,
function
(
err
){
getEsenceThreads
(
ent_code
,
tyhread_redis_salt
,
function
(
err
){
redis
.
get
(
key
,
function
(
error
,
res
){
return
callback
&&
callback
(
error
,
res
.
split
(
","
));
});
...
...
@@ -62,8 +95,8 @@ exports.get=function(ent_code,keyID,type,callback){
});
};
exports
.
set
=
function
(
ent_code
,
keyID
,
type
,
value
,
callback
){
var
key
=
getKey
(
ent_code
,
keyID
,
type
);
exports
.
set
=
function
(
ent_code
,
salt
,
value
,
callback
){
var
key
=
getKey
(
ent_code
,
salt
);
if
(
!
redis
){
console
.
log
(
'redis error'
);
return
callback
&&
callback
(
'error'
);
...
...
@@ -74,8 +107,8 @@ exports.set=function(ent_code,keyID,type,value,callback){
});
};
exports
.
clear
=
function
(
ent_code
,
keyID
,
type
,
callback
){
var
key
=
getKey
(
ent_code
,
keyID
,
type
);
exports
.
clear
=
function
(
ent_code
,
salt
,
callback
){
var
key
=
getKey
(
ent_code
,
salt
);
if
(
!
redis
){
console
.
log
(
'redis error'
);
return
callback
&&
callback
(
'error'
);
...
...
@@ -85,53 +118,24 @@ exports.clear = function(ent_code,keyID,type,callback){
});
};
function
getEsenceThreads
(
ent_code
,
keyID
,
type
,
callback
){
var
today
=
new
Date
();
var
conditions
=
{
ent_code
:
ent_code
,
level
:
1
,
status
:
1
,
new_recommend
:
1
,
$or
:
[{
isEvent
:
0
},
{
isEvent
:
null
},
{
isEvent
:
1
,
'event.eventStartTime'
:
{
$lte
:
today
}
}]
};
forumThreadService
.
getThreadWithNotPopulateComment
(
conditions
,
1
,
ThreadRedisCount
,
sort
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
);
}
else
{
util
.
loadLevel
(
ent_code
,
results
.
items
,
function
()
{
setToRedis
(
ent_code
,
keyID
,
type
,
JSON
.
stringify
(
results
));
callback
(
null
);
});
}
});
};
//获取缓存列表
exports
.
getRedisEsenceThreads
=
function
(
ent_code
,
keyID
,
type
,
callback
){
var
key
=
getKey
(
ent_code
,
keyID
,
type
);
getEsenceThreads
(
ent_code
,
keyID
,
type
,
function
(
err
){
exports
.
getRedisEsenceThreads
=
function
(
ent_code
,
callback
){
var
key
=
getKey
(
ent_code
,
tyhread_redis_salt
);
getEsenceThreads
(
ent_code
,
tyhread_redis_salt
,
function
(
err
){
redis
.
get
(
key
,
function
(
error
,
res
){
return
callback
&&
callback
(
error
,
res
.
split
(
","
));
});
});
};
//更新缓存列表
/*exports.updateRedisEsenceThreads = function(ent_code,keyID,type,callback){
getEsenceThreads(ent_code, keyID,type, function(err){
callback();
});
};*/
//获取缓存数值
exports
.
getThreadRedisCount
=
function
(){
return
ThreadRedisCount
;
};
//更新缓存列表
exports
.
updateRedisEsenceThreads
=
function
(
ent_code
){
if
(
RefreshFlag
){
getEsenceThreads
(
ent_code
,
tyhread_redis_salt
,
function
(
err
){});
}
};
\ No newline at end of file
strong
@strong
mentioned in commit
1b50346c
·
Mar 10, 2016
mentioned in commit
1b50346c
mentioned in commit 1b50346c57229827765b67e1b9d556faa80353af
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment