Skip to content

Commit

Permalink
refactor: 반복 횟수 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
kiarakim committed Oct 19, 2023
1 parent 225189a commit 3b77a70
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,10 @@ public List<StationPoint> findStationPoints(int page, int size) {
.limit(size)
.fetch();
}

public Long findStationCount() {
return jpaQueryFactory.select(station.stationId.count())
.from(station)
.fetchOne();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
@Service
public class StationGridFacadeService {

private static final int BATCH_SIZE = 1000;

private final StationGridService stationGridService;
private final StationQueryService stationQueryService;
private final StationGridCacheService stationGridCacheService;
Expand All @@ -40,17 +42,19 @@ public List<GridWithCount> createGridWithCounts() {
List<Grid> grids = gridGenerator.createKorea();
List<CompletableFuture<Void>> futures = new ArrayList<>();

int size = 1000;
int loopSize = stationQueryService.findStationCount().intValue() / BATCH_SIZE;

int page = 0;
while (size == 1000) {
for (int i = 0; i < loopSize; i++) {
int finalPage = page;
List<StationPoint> stationPoints = stationQueryService.findStationPoint(finalPage, size);
CompletableFuture<Void> future = CompletableFuture.runAsync(() -> stationGridService.assignStationGrids(grids, stationPoints), executor);

CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
List<StationPoint> stationPoints = stationQueryService.findStationPoint(finalPage, BATCH_SIZE);
stationGridService.assignStationGrids(grids, stationPoints);
}, executor);
futures.add(future);
page++;
size = stationPoints.size();
}

futures.forEach(CompletableFuture::join);
executor.shutdown();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.carffeine.carffeine.station.service.station;

import com.carffeine.carffeine.city.infrastructure.repository.CityQueryRepository;
import com.carffeine.carffeine.city.infrastructure.repository.dto.CitySearchResponse;
import com.carffeine.carffeine.station.domain.charger.ChargerType;
import com.carffeine.carffeine.station.domain.station.Coordinate;
import com.carffeine.carffeine.station.domain.station.Region;
import com.carffeine.carffeine.station.exception.StationException;
import com.carffeine.carffeine.station.exception.StationExceptionType;
import com.carffeine.carffeine.city.infrastructure.repository.CityQueryRepository;
import com.carffeine.carffeine.station.infrastructure.repository.station.StationQueryRepository;
import com.carffeine.carffeine.station.infrastructure.repository.station.dto.RegionMarker;
import com.carffeine.carffeine.station.infrastructure.repository.station.dto.StationInfo;
Expand All @@ -14,7 +15,6 @@
import com.carffeine.carffeine.station.infrastructure.repository.station.dto.StationSimpleResponse;
import com.carffeine.carffeine.station.infrastructure.repository.station.dto.StationSpecificResponse;
import com.carffeine.carffeine.station.infrastructure.repository.station.dto.StationSummaryResponse;
import com.carffeine.carffeine.city.infrastructure.repository.dto.CitySearchResponse;
import com.carffeine.carffeine.station.service.station.dto.CoordinateRequest;
import com.carffeine.carffeine.station.service.station.dto.StationSearchResponse;
import com.carffeine.carffeine.station.service.station.dto.StationsSearchResponse;
Expand Down Expand Up @@ -104,4 +104,8 @@ public List<RegionMarker> findMarkersByRegions(List<String> regionNames) {
public List<StationPoint> findStationPoint(int page, int size) {
return stationQueryRepository.findStationPoints(page, size);
}

public Long findStationCount() {
return stationQueryRepository.findStationCount();
}
}

0 comments on commit 3b77a70

Please sign in to comment.