diff --git a/CHANGELOG.md b/CHANGELOG.md index b113c7ca..85b4caf6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,10 @@ Ref: https://keepachangelog.com/en/1.0.0/ * Refactor account processing implementation to be more efficient [#552](https://github.com/provenance-io/explorer-service/issues/552) * Update keep alive times for flow api grpc calls [#558](https://github.com/provenance-io/explorer-service/pull/558) +### Bug Fixes + +* Fix pagination off by one calls to flow grpc [#561](https://github.com/provenance-io/explorer-service/pull/561) + ## [v5.11.0](https://github.com/provenance-io/explorer-service/releases/tag/v5.11.0) - 2024-08-27 ### Improvements diff --git a/service/src/main/kotlin/io/provenance/explorer/grpc/flow/FlowApiGrpcClient.kt b/service/src/main/kotlin/io/provenance/explorer/grpc/flow/FlowApiGrpcClient.kt index e911a71d..4f5fe963 100644 --- a/service/src/main/kotlin/io/provenance/explorer/grpc/flow/FlowApiGrpcClient.kt +++ b/service/src/main/kotlin/io/provenance/explorer/grpc/flow/FlowApiGrpcClient.kt @@ -65,7 +65,6 @@ class FlowApiGrpcClient(flowApiChannelUri: URI) { val allNavEvents = mutableListOf() var currentPage = 0 var hasMorePages = true - while (hasMorePages) { val pagination = PaginationRequest.newBuilder().setPage(currentPage).setPageSize(requestSize).build() val requestBuilder = NavEventRequest.newBuilder() @@ -80,8 +79,7 @@ class FlowApiGrpcClient(flowApiChannelUri: URI) { logger().debug("getAllMarkerNavByPriceDenoms $request") val response: NavEventResponse = navService.getNavEvents(request) allNavEvents.addAll(response.navEventsList) - - if (response.pagination.currentPage >= response.pagination.totalPages) { + if (response.pagination.currentPage >= response.pagination.totalPages - 1) { hasMorePages = false } else { currentPage++ @@ -91,7 +89,6 @@ class FlowApiGrpcClient(flowApiChannelUri: URI) { hasMorePages = false } } - return@runBlocking allNavEvents } @@ -115,15 +112,22 @@ class FlowApiGrpcClient(flowApiChannelUri: URI) { } } - fun getAllLatestNavPrices(priceDenom: String, includeMarkers: Boolean = true, includeScopes: Boolean = true, fromDate: DateTime?, requestSize: Int = 10000): List = runBlocking { + fun getAllLatestNavPrices( + priceDenom: String, + includeMarkers: Boolean = true, + includeScopes: Boolean = true, + fromDate: DateTime?, + requestSize: Int = 10000 + ): List = runBlocking { val fromDateString = fromDate?.toString(DateTimeFormat.forPattern("yyyy-MM-dd")) ?: "" - var currentPage = 1 - var totalPages = 1 + var currentPage = 0 + var hasMorePages = true val allNavEvents = mutableListOf() - try { - while (currentPage <= totalPages) { - val pagination = PaginationRequest.newBuilder().setPage(currentPage).setPageSize(requestSize).build() + while (hasMorePages) { + try { + val pagination = + PaginationRequest.newBuilder().setPage(currentPage).setPageSize(requestSize).build() val request = LatestNavEventRequest.newBuilder() .setPriceDenom(priceDenom) .setFromDate(fromDateString) @@ -135,17 +139,17 @@ class FlowApiGrpcClient(flowApiChannelUri: URI) { logger().debug("getLatestNavEvents $request") val response: NavEventResponse = navService.getLatestNavEvents(request) - allNavEvents.addAll(response.navEventsList) - currentPage++ - totalPages = response.pagination.totalPages + if (response.pagination.currentPage >= response.pagination.totalPages - 1) { + hasMorePages = false + } else { + currentPage++ + } + } catch (e: Exception) { + logger().error("Error fetching latest Nav Events: ${e.message}", e) } - logger().debug("getLatestNavEvents finished total pages requested: $currentPage total navs: ${allNavEvents.size}") - return@runBlocking allNavEvents - } catch (e: Exception) { - logger().error("Error fetching latest Nav Events: ${e.message}", e) - emptyList() } + return@runBlocking allNavEvents } } diff --git a/service/src/main/kotlin/io/provenance/explorer/service/AssetService.kt b/service/src/main/kotlin/io/provenance/explorer/service/AssetService.kt index 435ae8f2..2bf4f7f2 100644 --- a/service/src/main/kotlin/io/provenance/explorer/service/AssetService.kt +++ b/service/src/main/kotlin/io/provenance/explorer/service/AssetService.kt @@ -250,7 +250,6 @@ class AssetService( includeScopes = false, fromDate = assetPricinglastRun?.toDateTime() ) - latestPrices.forEach { price -> if (price.denom != UTILITY_TOKEN) { val marker = getAssetRaw(price.denom)