1、优化帖子阅读计数,让帖子阅读数更准确
2、更新最新redkale-plugins.jar,加入redis验权
This commit is contained in:
parent
ad73300a25
commit
624f4ec220
24
README.md
24
README.md
@ -1,8 +1,18 @@
|
||||
# redbbs
|
||||
|
||||
2018-06-17更新
|
||||
社区升级
|
||||
1、表字段统一小写,
|
||||
2、表模块划分
|
||||
3、表状态等字段统一smallint
|
||||
# redbbs
|
||||
|
||||
2018-07-01更新
|
||||
1、优化帖子阅读计数,让帖子阅读数更准确
|
||||
2、更新最新redkale-plugins.jar,加入redis验权
|
||||
|
||||
2018-06-30更新
|
||||
1、修改servlet层中BaseServlet中共享request的重大bug
|
||||
2、将servlet中页面统一使用HttpScope进行渲染
|
||||
3、优化帖子阅读计数,让帖子阅读数更准确
|
||||
4、更新最新redkale-plugins.jar,加入redis验权
|
||||
|
||||
2018-06-17更新
|
||||
社区升级
|
||||
1、表字段统一小写,
|
||||
2、表模块划分
|
||||
3、表状态等字段统一smallint
|
||||
4、部分字段值重新定义
|
@ -6,11 +6,11 @@
|
||||
|
||||
<resources>
|
||||
<source name="redis" value="org.redkalex.cache.RedisCacheSource" xxx="16">
|
||||
<node addr="redishost" port="6379"/>
|
||||
<node addr="redishost" port="6379" password="pwd123"/>
|
||||
</source>
|
||||
|
||||
<properties>
|
||||
<property name="mongo.host" value="127.0.0.1"/>
|
||||
<property name="mongo.host" value="redishost"/>
|
||||
<property name="mongo.database" value="redbbs"/>
|
||||
</properties>
|
||||
</resources>
|
||||
|
Binary file not shown.
BIN
libs/redbbs.jar
BIN
libs/redbbs.jar
Binary file not shown.
@ -75,6 +75,12 @@ public class BaseServlet extends HttpServlet {
|
||||
visLog.set("userid", userid);
|
||||
visLog.set("uri", request.getRequestURI());
|
||||
|
||||
Kv headers = Kv.create();
|
||||
request.getHeaders().forEach((k,v)->{
|
||||
headers.set(k, request.getHeader(k));
|
||||
});
|
||||
visLog.set("headers", headers);
|
||||
|
||||
Kv para = Kv.create();
|
||||
for (String key : request.getParameterNames()){
|
||||
para.set(key, request.getParameter(key));
|
||||
|
@ -1,20 +1,30 @@
|
||||
package com.lxyer.bbs.base;
|
||||
|
||||
import com.lxyer.bbs.content.Content;
|
||||
import com.lxyer.bbs.content.ContentService;
|
||||
import com.mongodb.MongoClient;
|
||||
import com.mongodb.client.MongoCollection;
|
||||
import com.mongodb.client.MongoDatabase;
|
||||
import org.bson.Document;
|
||||
import org.bson.conversions.Bson;
|
||||
import org.redkale.source.ColumnValue;
|
||||
import org.redkale.util.AnyValue;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
import static com.mongodb.client.model.Filters.*;
|
||||
|
||||
/**
|
||||
* Created by liangxianyou at 2018/6/20 22:54.
|
||||
*/
|
||||
public class TaskQueue<T extends Object> extends BaseService implements Runnable {
|
||||
|
||||
@Resource
|
||||
private ContentService contentService;
|
||||
|
||||
@Resource(name = "property.mongo.host")
|
||||
private String mongoHost;
|
||||
@Resource(name = "property.mongo.database")
|
||||
@ -49,15 +59,44 @@ public class TaskQueue<T extends Object> extends BaseService implements Runnable
|
||||
public void run() {
|
||||
try {
|
||||
while (true){
|
||||
Map take = (Map) take();
|
||||
Map logData = (Map) take();
|
||||
|
||||
take.put("ftime", String.format("%1$tY%1$tm%1$td%1$tH%1$tM%1$tS", take.get("time")));
|
||||
visLog.insertOne(new Document(take));
|
||||
logData.put("ftime", String.format("%1$tY%1$tm%1$td%1$tH%1$tM%1$tS", logData.get("time")));
|
||||
visLog.insertOne(new Document(logData));
|
||||
|
||||
//在这里处理日志数据[访问量]
|
||||
//在这里处理日志数据
|
||||
String uri = logData.get("uri")+"";
|
||||
|
||||
//[访问量]
|
||||
if (uri.startsWith("/jie/detail/")){
|
||||
updateViewNumAsync(logData);
|
||||
}
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 帖子阅读数处理
|
||||
* @param logData
|
||||
*/
|
||||
private void updateViewNumAsync(Map logData) {
|
||||
CompletableFuture.runAsync(()->{
|
||||
Bson filter = and(
|
||||
eq("uri", logData.get("uri"))//帖子
|
||||
,eq("ip", logData.get("ip"))//IP
|
||||
,or(
|
||||
eq("userid", logData.get("userid"))//登录人
|
||||
,eq("userid", 0)//未登录userid=0
|
||||
)
|
||||
);
|
||||
long count = visLog.count(filter);
|
||||
if (count <= 1){
|
||||
String uri = logData.get("uri") + "";
|
||||
int contentid = Integer.parseInt(uri.replace("/jie/detail/", ""));
|
||||
source.updateColumn(Content.class, contentid, ColumnValue.inc("viewnum", 1));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package com.lxyer.bbs.servlet;
|
||||
|
||||
import com.jfinal.kit.Kv;
|
||||
import com.lxyer.bbs.base.BaseServlet;
|
||||
import com.lxyer.bbs.base.user.UserRecord;
|
||||
import com.lxyer.bbs.comment.CommentInfo;
|
||||
import com.lxyer.bbs.content.ContentInfo;
|
||||
import org.redkale.net.http.*;
|
||||
@ -10,9 +9,6 @@ import org.redkale.source.FilterNode;
|
||||
import org.redkale.source.Flipper;
|
||||
import org.redkale.util.Sheet;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static org.redkale.source.FilterExpress.NOTEQUAL;
|
||||
|
||||
/**
|
||||
@ -67,17 +63,6 @@ public class ContentServlet extends BaseServlet {
|
||||
Flipper flipper3 = new Flipper().limit(8).sort("replynum DESC");
|
||||
Sheet<ContentInfo> hotReply = contentService.contentQuery(flipper3, "", sessionid);
|
||||
|
||||
//更新
|
||||
CompletableFuture.supplyAsync(new Supplier<String>() {
|
||||
@Override
|
||||
public String get() {
|
||||
UserRecord user = request.currentUser();
|
||||
if (user == null || user.getRoleid() != 0)
|
||||
contentService.incrViewNum(contentid);
|
||||
return "";
|
||||
}
|
||||
});
|
||||
|
||||
Kv kv = Kv.by("bean", content).set("comments", comments)/*.set("hotView", hotView)*/.set("hotReply", hotReply);
|
||||
response.finish(HttpScope.refer("/jie/detail.html").attr(kv));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user