Skip to content
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

#13 save with batches #16

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.kvsinyuk.elasticsearch.adapter.out.mongo

import com.kvsinyuk.elasticsearch.application.port.SaveDealPort
import com.kvsinyuk.elasticsearch.domain.Deal
import org.bson.types.ObjectId
import org.springframework.data.mongodb.repository.MongoRepository

interface DealRepository : MongoRepository<Deal, ObjectId>, SaveDealPort
interface DealRepository : MongoRepository<Deal, ObjectId>
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
package com.kvsinyuk.elasticsearch.application.impl

import com.kvsinyuk.elasticsearch.adapter.out.mongo.DealRepository
import com.kvsinyuk.elasticsearch.application.port.GenerateDealsUseCase
import com.kvsinyuk.elasticsearch.application.port.SaveDealPort
import com.kvsinyuk.elasticsearch.utils.generateDeal
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.springframework.beans.factory.annotation.Value
import org.springframework.stereotype.Component

@Component
class GenerateDealsUseCaseImpl(
private val saveDealPort: SaveDealPort
private val dealRepository: DealRepository
): GenerateDealsUseCase {

@Value("\${generator.batch.count}")
private var batchCount: Int = 20

override fun generateDeals(dealAmount: Int) {
for (i in 0 until dealAmount) {
for (i in dealAmount downTo batchCount) {
CoroutineScope(Dispatchers.Default).launch {
saveDealPort.save(generateDeal())
(0 until batchCount)
.map { generateDeal() }
.let { dealRepository.saveAll(it) }
}
}
}
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@

generator.batch.count: 100
Loading