File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ import app.utils.EmptyRepoException
16
16
import app.utils.FileHelper.toPath
17
17
import app.utils.HashingException
18
18
import app.utils.RepoHelper
19
+ import app.utils.batch
19
20
import org.eclipse.jgit.api.Git
20
21
import java.io.File
21
22
import java.io.IOException
@@ -145,7 +146,9 @@ class RepoHasher(private val api: Api,
145
146
private fun postAuthorsToServer (authors : HashSet <Author >,
146
147
serverRepo : Repo ) {
147
148
authors.forEach { author -> author.repo = serverRepo }
148
- api.postAuthors(authors.toList()).onErrorThrow()
149
+ for (authorsBatch in authors.asSequence().batch(1000 )) {
150
+ api.postAuthors(authorsBatch).onErrorThrow()
151
+ }
149
152
}
150
153
151
154
private fun initServerRepo (localRepo : LocalRepo ,
Original file line number Diff line number Diff line change
1
+ // Copyright 2018 Sourcerer Inc. All Rights Reserved.
2
+ // Author: Anatoly Kislov ([email protected] )
3
+
4
+ package app.utils
5
+
6
+ // TODO(anatoly): Replace with chunked from new Kotlin version.
7
+ // SO #34498368 @ Jayson Minard.
8
+ fun <T > Sequence<T>.batch (n : Int ): Sequence <List <T >> {
9
+ return BatchingSequence (this , n)
10
+ }
11
+
12
+ class BatchingSequence <T >(val source : Sequence <T >,
13
+ val batchSize : Int ) : Sequence<List<T>> {
14
+ override fun iterator (): Iterator <List <T >> = object :
15
+ AbstractIterator <List <T >>() {
16
+ val iterate = if (batchSize > 0 ) source.iterator() else
17
+ emptyList<T >().iterator()
18
+ override fun computeNext () {
19
+ if (iterate.hasNext()) setNext(iterate.asSequence()
20
+ .take(batchSize).toList())
21
+ else done()
22
+ }
23
+ }
24
+ }
You can’t perform that action at this time.
0 commit comments