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

Search Index Optimizations #18649

Merged
merged 4 commits into from
Nov 18, 2024
Merged

Search Index Optimizations #18649

merged 4 commits into from
Nov 18, 2024

Conversation

mohityadav766
Copy link
Contributor

Describe your changes:

Fixes

I worked on ... because ...

Type of change:

  • Bug fix
  • Improvement
  • New feature
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes <issue-number>: <short explanation>
  • I have commented on my code, particularly in hard-to-understand areas.
  • For JSON Schema changes: I updated the migration scripts or explained why it is not needed.

Copy link

sonarcloud bot commented Nov 18, 2024

@harshach harshach merged commit ae1e7e6 into main Nov 18, 2024
16 of 18 checks passed
@harshach harshach deleted the index-optimizations branch November 18, 2024 17:07
Comment on lines +133 to +142
for (int i = 0; i < response.getItems().length; i++) {
BulkItemResponse itemResponse = response.getItems()[i];
if (itemResponse.isFailed()) {
String failureMessage = itemResponse.getFailureMessage();
String entityData = requests.get(i).toString();
entityErrorList.add(
new EntityError().withMessage(failureMessage).withEntity(entityData));
LOG.warn("Bulk item failed: {}", failureMessage);
}
}
Copy link
Contributor

@TeddyCr TeddyCr Nov 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of using a Stream here like this (caveat i have not tested it)

entityErrorList = response.getItems().length > 0 ? response.getItems()
.stream()
.filter(BulkItemResponse::isFailed)
.map(
    item -> {
        int idx = Arrays.asList(response.getItems()).indexOf(item);
       String failureMessage =  itemResponse.getFailureMessage()
        EntityError().withMessage(itemResponse.getFailureMessage()).withEntity(request.get(idx).toString)
        LOG.warn("Bulk item failed: {}", failureMessage);
   }).toList() : entityErrorList;

Also do you know if List<EntityError> entityErrorList will be mutable and how it will behave with the multithreading?

Comment on lines +146 to +150
for (BulkItemResponse item : response.getItems()) {
if (item.isFailed()) {
failed++;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we do something like

int failed = entityErrorList.size()

I believe this prevents us from looping twice over the response

Comment on lines +234 to +243
for (int i = 0; i < response.getItems().length; i++) {
BulkItemResponse itemResponse = response.getItems()[i];
if (itemResponse.isFailed()) {
String failureMessage = itemResponse.getFailureMessage();
String entityData = bulkRequest.requests().get(i).toString();
entityErrorList.add(
new EntityError().withMessage(failureMessage).withEntity(entityData));
LOG.warn("Bulk item failed on retry {}: {}", attempt, failureMessage);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +247 to +251
for (BulkItemResponse item : response.getItems()) {
if (item.isFailed()) {
failed++;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend safe to test Add this label to run secure Github workflows on PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants