@@ -301,13 +301,9 @@ class ModelClientV2(
301
301
return IStream .useSequencesSuspending {
302
302
version.write()
303
303
val objects = version.fullDiff(baseVersion)
304
- val delta = if (true /* objects.size > 1000 */ ) {
305
- // large HTTP requests and large Json objects don't scale well
306
- pushObjects(branch.repositoryId, objects.map { it.hash to it.serialize() })
307
- VersionDelta (version.getContentHash(), null )
308
- } else {
309
- VersionDelta (version.getContentHash(), null , objectsMap = objects.toMap({ it.hash }, { it.serialize() }).getSuspending())
310
- }
304
+ // large HTTP requests and large Json objects don't scale well
305
+ val lastChunk = pushObjects(branch.repositoryId, objects.map { it.hash to it.serialize() }, returnLastChunk = true )
306
+ val delta = VersionDelta (version.getContentHash(), null , objectsMap = lastChunk.toMap())
311
307
httpClient.preparePost {
312
308
url {
313
309
takeFrom(baseUrl)
@@ -323,13 +319,18 @@ class ModelClientV2(
323
319
}
324
320
325
321
override suspend fun pushObjects (repository : RepositoryId , objects : Sequence <ObjectHashAndSerializedObject >) {
326
- pushObjects(repository, IStream .many(objects))
322
+ pushObjects(repository, IStream .many(objects), false )
327
323
}
328
324
329
- private suspend fun pushObjects (repository : RepositoryId , objects : IStream .Many <ObjectHashAndSerializedObject >) {
325
+ /* *
326
+ * If the last chunk is smaller than #minBodySize, then the remaining objects are returned for inlining in the
327
+ * main request.
328
+ */
329
+ private suspend fun pushObjects (repository : RepositoryId , objects : IStream .Many <ObjectHashAndSerializedObject >, returnLastChunk : Boolean ): List <ObjectHashAndSerializedObject > {
330
330
LOG .debug { " ${clientId.toString(16 )} .pushObjects($repository )" }
331
331
val maxBodySize = 2 * 1024 * 1024
332
332
val chunkContent = StringBuilder ()
333
+ val chunkEntries = ArrayList <ObjectHashAndSerializedObject >()
333
334
334
335
suspend fun sendChunk () {
335
336
httpClient.put {
@@ -341,6 +342,7 @@ class ModelClientV2(
341
342
setBody(chunkContent.toString())
342
343
}
343
344
chunkContent.clear()
345
+ chunkEntries.clear()
344
346
}
345
347
346
348
objects.asSequence().forEach { entry ->
@@ -350,8 +352,12 @@ class ModelClientV2(
350
352
}
351
353
if (chunkContent.isNotEmpty()) chunkContent.append(' \n ' )
352
354
chunkContent.append(entry.first).append(' \n ' ).append(entry.second)
355
+ chunkEntries.add(entry)
356
+ }
357
+ if (chunkContent.isNotEmpty() && ! returnLastChunk) {
358
+ sendChunk()
353
359
}
354
- if (chunkContent.isNotEmpty()) sendChunk()
360
+ return chunkEntries
355
361
}
356
362
357
363
override suspend fun pull (branch : BranchReference , lastKnownVersion : IVersion ? ): IVersion {
0 commit comments