Skip to content

Commit

Permalink
[UNI-255] refactor: 캐시 로직 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
mikekks committed Feb 20, 2025
1 parent e2aa5b1 commit 0b00fb5
Showing 1 changed file with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.softeer5.uniro_backend.map.entity.Route;
import com.softeer5.uniro_backend.map.repository.RouteRepository;
import com.softeer5.uniro_backend.map.service.vo.LightRoute;
import com.softeer5.uniro_backend.map.service.vo.LightRoutes;

import lombok.RequiredArgsConstructor;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
Expand Down Expand Up @@ -88,20 +89,32 @@ public GetAllRoutesResDTO getAllRoutesByLocalCache(Long univId) {
}

public GetAllRoutesResDTO getAllRoutes(Long univId) {
List<Route> routes = routeRepository.findAllRouteByUnivIdWithNodes(univId);

if(!redisService.hasData(univId.toString())){
List<Route> routes = routeRepository.findAllRouteByUnivIdWithNodes(univId);
List<LightRoute> lightRoutes = routes.stream().map(LightRoute::new).toList();
LightRoutes value = new LightRoutes(lightRoutes);
redisService.saveData(univId.toString(), value);
}
else{
log.info("🚀🚀🚀🚀🚀🚀🚀HIT🚀🚀🚀🚀🚀🚀🚀");
}

LightRoutes lightRoutes = (LightRoutes) redisService.getData(univId.toString());
List<LightRoute> routes = lightRoutes.getLightRoutes();

// 맵이 존재하지 않을 경우 예외
if(routes.isEmpty()) {
throw new RouteException("Route Not Found", ROUTE_NOT_FOUND);
}

RevInfo revInfo = revInfoRepository.findFirstByUnivIdOrderByRevDesc(univId)
.orElseThrow(() -> new RouteException("Revision not found", RECENT_REVISION_NOT_FOUND));
.orElseThrow(() -> new RouteException("Revision not found", RECENT_REVISION_NOT_FOUND));

AllRoutesInfo allRoutesInfo = routeCalculator.assembleRoutes(routes);
AllRoutesInfo allRoutesInfo = routeCacheCalculator.assembleRoutes(routes);

return GetAllRoutesResDTO.of(allRoutesInfo.getNodeInfos(), allRoutesInfo.getCoreRoutes(),
allRoutesInfo.getBuildingRoutes(), revInfo.getRev());
allRoutesInfo.getBuildingRoutes(), revInfo.getRev());
}

@Async
Expand Down

0 comments on commit 0b00fb5

Please sign in to comment.