Skip to content

Commit

Permalink
Make some chunked xcontent more efficient (#115512) (#115736)
Browse files Browse the repository at this point in the history
  • Loading branch information
thecoop authored Oct 28, 2024
1 parent a97de99 commit 20470d0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,13 @@ public void writeTo(StreamOutput out) throws IOException {

@Override
public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params params) {
return ChunkedToXContent.builder(params).object(ob -> {
ob.field(ERRORS, hasFailures());
ob.field(TOOK, tookInMillis);
return ChunkedToXContent.builder(params).object(ob -> ob.append((b, p) -> {
b.field(ERRORS, hasFailures());
b.field(TOOK, tookInMillis);
if (ingestTookInMillis != BulkResponse.NO_INGEST_TOOK) {
ob.field(INGEST_TOOK, ingestTookInMillis);
b.field(INGEST_TOOK, ingestTookInMillis);
}
ob.array(ITEMS, Iterators.forArray(responses));
});
return b;
}).array(ITEMS, Iterators.forArray(responses)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,15 @@ private void endObject() {
* Creates an object, with the specified {@code contents}
*/
public ChunkedToXContentBuilder xContentObject(ToXContent contents) {
startObject();
append(contents);
endObject();
addChunk((b, p) -> contents.toXContent(b.startObject(), p).endObject());
return this;
}

/**
* Creates an object named {@code name}, with the specified {@code contents}
*/
public ChunkedToXContentBuilder xContentObject(String name, ToXContent contents) {
startObject(name);
append(contents);
endObject();
addChunk((b, p) -> contents.toXContent(b.startObject(name), p).endObject());
return this;
}

Expand Down

0 comments on commit 20470d0

Please sign in to comment.