Skip to content

Commit

Permalink
perf: 对查询仪表盘访问趋势信息接口增加缓存处理
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles7c committed Sep 9, 2023
1 parent a1c20af commit 1722133
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,9 @@ public class CacheConsts {
* 菜单缓存键前缀
*/
public static final String MENU_KEY_PREFIX = "MENU";

/**
* 仪表盘缓存键前缀
*/
public static final String DASHBOARD_KEY_PREFIX = "DASHBOARD";
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
import java.util.stream.Collectors;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.NumberUtil;

import top.charles7c.cnadmin.common.constant.CacheConsts;
import top.charles7c.cnadmin.monitor.model.vo.DashboardAccessTrendVO;
import top.charles7c.cnadmin.monitor.model.vo.DashboardGeoDistributionVO;
import top.charles7c.cnadmin.monitor.model.vo.DashboardPopularModuleVO;
Expand All @@ -44,9 +46,9 @@
* @author Charles7c
* @since 2023/9/8 21:32
*/
@Slf4j
@Service
@RequiredArgsConstructor
@CacheConfig(cacheNames = CacheConsts.DASHBOARD_KEY_PREFIX)
public class DashboardServiceImpl implements DashboardService {

private final LogService logService;
Expand All @@ -65,6 +67,7 @@ public DashboardTotalVO getTotal() {
}

@Override
@Cacheable(key = "#days")
public List<DashboardAccessTrendVO> listAccessTrend(Integer days) {
return logService.listDashboardAccessTrend(days);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
COUNT(DISTINCT `client_ip`) AS ipCount
FROM `sys_log`
GROUP BY DATE(`create_time`)
HAVING `date` != CURDATE()
ORDER BY DATE(`create_time`) DESC
LIMIT #{days}
</select>
Expand Down

0 comments on commit 1722133

Please sign in to comment.