Skip to content

chore: tests for batching and deduplication by field selection #1449

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
feat: update tests
  • Loading branch information
samvazquez committed May 27, 2022
commit fb2b796d23ff3f4b84c954dc5e79a71f5364c264
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import java.time.Duration
import java.util.Optional

object ProductRepository {
private val properties = listOf(
private val products = listOf(
Product(
1,
ProductSummary("Product 1"),
Expand All @@ -36,25 +36,25 @@ object ProductRepository {
fun getProducts(requests: List<ProductServiceRequest>): Flux<Optional<Product>> {
val reducedRequests = requests
.groupBy(ProductServiceRequest::id)
.mapValues { (propertyId, requests) ->
.mapValues { (productId, requests) ->
ProductServiceRequest(
propertyId,
productId,
requests.map(ProductServiceRequest::fields).flatten().distinct()
)
}.values.toList()

val results = reducedRequests.mapNotNull { propertyRequest ->
properties
.firstOrNull { it.id == propertyRequest.id }
val results = reducedRequests.mapNotNull { productRequest ->
products
.firstOrNull { it.id == productRequest.id }
?.let { property ->
Product(
property.id,
when {
propertyRequest.fields.contains("summary") -> property.summary
productRequest.fields.contains("summary") -> property.summary
else -> null
},
when {
propertyRequest.fields.contains("details") -> property.details
productRequest.fields.contains("details") -> property.details
else -> null
}
)
Expand Down