use of org.codelibs.fess.es.log.exbhv.UserInfoBhv in project fess by codelibs.
the class SearchLogHelper method updateUserInfo.
public void updateUserInfo(final String userCode) {
final long current = System.currentTimeMillis();
final Long time = userInfoCache.get(userCode);
if (time == null || current - time.longValue() > userCheckInterval) {
final UserInfoBhv userInfoBhv = ComponentUtil.getComponent(UserInfoBhv.class);
final LocalDateTime now = ComponentUtil.getSystemHelper().getCurrentTimeAsLocalDateTime();
userInfoBhv.selectByPK(userCode).ifPresent(userInfo -> {
userInfo.setUpdatedAt(now);
new Thread(() -> {
userInfoBhv.insertOrUpdate(userInfo);
}).start();
}).orElse(() -> {
final UserInfo userInfo = new UserInfo();
userInfo.setId(userCode);
userInfo.setCreatedAt(now);
userInfo.setUpdatedAt(now);
userInfoBhv.insert(userInfo);
});
userInfoCache.put(userCode, current);
}
}
use of org.codelibs.fess.es.log.exbhv.UserInfoBhv in project fess by codelibs.
the class SearchLogHelper method processSearchLogQueue.
protected void processSearchLogQueue(final Queue<SearchLog> queue) {
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final String value = fessConfig.getPurgeByBots();
String[] botNames;
if (StringUtil.isBlank(value)) {
botNames = StringUtil.EMPTY_STRINGS;
} else {
botNames = value.split(",");
}
final List<SearchLog> searchLogList = new ArrayList<>();
final Map<String, UserInfo> userInfoMap = new HashMap<>();
queue.stream().forEach(searchLog -> {
final String userAgent = searchLog.getUserAgent();
final boolean isBot = userAgent != null && stream(botNames).get(stream -> stream.anyMatch(botName -> userAgent.indexOf(botName) >= 0));
if (!isBot) {
searchLog.getUserInfo().ifPresent(userInfo -> {
final String code = userInfo.getId();
final UserInfo oldUserInfo = userInfoMap.get(code);
if (oldUserInfo != null) {
userInfo.setCreatedAt(oldUserInfo.getCreatedAt());
}
userInfoMap.put(code, userInfo);
});
searchLogList.add(searchLog);
}
});
if (!userInfoMap.isEmpty()) {
final List<UserInfo> insertList = new ArrayList<>(userInfoMap.values());
final List<UserInfo> updateList = new ArrayList<>();
final UserInfoBhv userInfoBhv = ComponentUtil.getComponent(UserInfoBhv.class);
userInfoBhv.selectList(cb -> {
cb.query().setId_InScope(userInfoMap.keySet());
cb.fetchFirst(userInfoMap.size());
}).forEach(userInfo -> {
final String code = userInfo.getId();
final UserInfo entity = userInfoMap.get(code);
entity.setId(userInfo.getId());
entity.setCreatedAt(userInfo.getCreatedAt());
updateList.add(entity);
insertList.remove(entity);
});
userInfoBhv.batchInsert(insertList);
userInfoBhv.batchUpdate(updateList);
searchLogList.stream().forEach(searchLog -> {
searchLog.getUserInfo().ifPresent(userInfo -> {
searchLog.setUserInfoId(userInfo.getId());
});
});
}
if (!searchLogList.isEmpty()) {
storeSearchLogList(searchLogList);
if (fessConfig.isSuggestSearchLog()) {
final SuggestHelper suggestHelper = ComponentUtil.getSuggestHelper();
suggestHelper.indexFromSearchLog(searchLogList);
}
}
}
Aggregations