Skip to content

No allocations in ResponseItem.IsValid property #7731

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

Merged
merged 1 commit into from
Jul 10, 2023
Merged
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
19 changes: 14 additions & 5 deletions src/Elastic.Clients.Elasticsearch/Api/ResponseItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.

using System;

namespace Elastic.Clients.Elasticsearch.Core.Bulk;

public abstract partial class ResponseItem
Expand All @@ -15,12 +17,19 @@ public bool IsValid
if (Error is not null)
return false;

return Operation.ToLowerInvariant() switch
var operation = Operation;

if (operation.Equals("delete", StringComparison.OrdinalIgnoreCase))
return Status is 200 or 404;

if (operation.Equals("create", StringComparison.OrdinalIgnoreCase) ||
operation.Equals("update", StringComparison.OrdinalIgnoreCase) ||
operation.Equals("index", StringComparison.OrdinalIgnoreCase))
{
"delete" => Status == 200 || Status == 404,
"update" or "index" or "create" => Status == 200 || Status == 201,
_ => false,
};
return Status is 200 or 201;
}

return false;
}
}
}