@@ -30,43 +30,25 @@ public class MapService {
3030 private final DiaryRepository diaryRepository ;
3131 private final RedisDao redisDao ;
3232
33- @ Transactional (readOnly = true )
34- public List <DiaryClusterResponseDto > getDiaryClusters (double south , double north , double west , double east , int zoom ) {
35- String redisKey ;
36- List <DiaryClusterResponseDto > clusters ;
37-
38- // 줌 레벨 기준으로 캐시 키 결정 + Redis 조회
33+ public List <DiaryClusterResponseDto > getDiaryClusters (
34+ double south , double north , double west , double east , int zoom ) {
3935 if (zoom <= 10 ) {
40- redisKey = "cluster:sido" ;
41- clusters = redisDao .getList (redisKey , DiaryClusterResponseDto .class );
42-
43- // 캐시에 없으면 DB 조회 후 저장
44- if (clusters == null ) {
45- clusters = sidoAreasRepository .findAllWithDiaryCount (); // 시/도 전체 조회
46- redisDao .setList (redisKey , clusters , Duration .ofMinutes (5 ));
47- log .info ("[REDIS] 시/도 클러스터 캐시 새로 저장: {}" , redisKey );
48- }
36+ return getSidoAreasClusters (south , north , west , east );
4937 } else {
50- redisKey = "cluster:sigg" ;
51- clusters = redisDao .getList (redisKey , DiaryClusterResponseDto .class );
52-
53- // 캐시에 없으면 DB 조회 후 저장
54- if (clusters == null ) {
55- clusters = siggAreasRepository .findAllWithDiaryCount (); // 시/군/구 전체 조회
56- redisDao .setList (redisKey , clusters , Duration .ofMinutes (5 ));
57- log .info ("[REDIS] 시/군/구 클러스터 캐시 새로 저장: {}" , redisKey );
58- }
38+ return getSiggAreasClusters (south , north , west , east );
5939 }
40+ }
6041
61- // 범위 필터링
62- return clusters .stream ()
63- .filter (cluster ->
64- cluster .lat () >= south && cluster .lat () <= north &&
65- cluster .lon () >= west && cluster .lon () <= east )
66- .toList ();
42+ private List <DiaryClusterResponseDto > getSidoAreasClusters (double south , double north , double west , double east ) {
43+ return sidoAreasRepository .findSidoAreaClusters (south , north , west , east );
6744 }
6845
69- @ Transactional
46+ private List <DiaryClusterResponseDto > getSiggAreasClusters (double south , double north , double west , double east ) {
47+ return siggAreasRepository .findSiggAreaClusters (south , north , west , east );
48+ }
49+
50+
51+ @ Transactional
7052 public void increaseRegionDiaryCount (Double lat , Double lon ) {
7153 sidoAreasRepository .findRegionByLatLon (lat , lon )
7254 .flatMap (sido -> sidoAreasDiaryCountRepository .findById (sido .getId ()))
0 commit comments