Skip to content

Commit

Permalink
Merge pull request #102 from cardano-foundation/feature/MET-2208-erro…
Browse files Browse the repository at this point in the history
…r-while-using-self-hosted-sanchonet-instance

fix: null pointer ex when poolFetchList from koios is empty
  • Loading branch information
Sotatek-DucPhung authored Jul 2, 2024
2 parents c23af4d + 671d0b6 commit b21cc2d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import io.micrometer.common.util.StringUtils;
import rest.koios.client.backend.api.base.exception.ApiException;
Expand Down Expand Up @@ -49,6 +50,10 @@ public CompletableFuture<Boolean> fetchData(List<String> poolIds) {
int currentEpoch = epochService.getCurrentEpoch();
var dataFromKoios = getPoolInfoList(poolIds);

if (CollectionUtils.isEmpty(dataFromKoios)) {
return CompletableFuture.completedFuture(Boolean.TRUE);
}

var poolHashMap =
poolHashRepository.findByViewIn(poolIds).stream()
.collect(Collectors.toMap(PoolHash::getView, Function.identity()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import io.micrometer.common.util.StringUtils;
import rest.koios.client.backend.api.base.exception.ApiException;
Expand Down Expand Up @@ -60,6 +61,10 @@ public CompletableFuture<Boolean> fetchData(String poolId) {
var dataFromKoios = getPoolHistoryList(poolId);
var poolHistoryCheckpoint = poolHistoryCheckpointRepository.findByView(poolId);

if (CollectionUtils.isEmpty(dataFromKoios)) {
return CompletableFuture.completedFuture(Boolean.TRUE);
}

Map<Integer, PoolHistory> poolHistoryList =
dataFromKoios.stream()
.filter(poolHistory -> poolHistory.getEpochNo() < currentEpoch)
Expand Down

0 comments on commit b21cc2d

Please sign in to comment.