Skip to content

Commit fbc24b1

Browse files
committed
fix: csharp
1 parent 942fc3f commit fbc24b1

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

clients/algoliasearch-client-csharp/algoliasearch/Utils/SearchClientExtensions.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,18 @@ public partial interface ISearchClient
176176
/// <inheritdoc cref="SaveObjectsAsync{T}(string, IEnumerable{T}, RequestOptions, CancellationToken)"/>
177177
List<BatchResponse> SaveObjects<T>(string indexName, IEnumerable<T> objects, bool waitForTasks = false, int batchSize = 1000, RequestOptions options = null, CancellationToken cancellationToken = default) where T : class;
178178

179+
/// <summary>
180+
/// Helper: Saves the given array of objects in the given index. The `chunkedBatch` helper is used under the hood, which creates a `batch` requests with at most 1000 objects in it.
181+
/// </summary>
182+
/// <param name="indexName">The index in which to perform the request.</param>
183+
/// <param name="objects">The list of `objects` to store in the given Algolia `indexName`.</param>
184+
/// <param name="options">Add extra http header or query parameters to Algolia.</param>
185+
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
186+
/// <typeparam name="T"></typeparam>
187+
List<BatchResponse> SaveObjectsAsync<T>(string indexName, IEnumerable<T> objects, RequestOptions options = null, CancellationToken cancellationToken = default) where T : class;
188+
/// <inheritdoc cref="SaveObjectsAsync{T}(string, IEnumerable{T}, RequestOptions, CancellationToken)"/>
189+
List<BatchResponse> SaveObjects<T>(string indexName, IEnumerable<T> objects, RequestOptions options = null, CancellationToken cancellationToken = default) where T : class;
190+
179191
/// <summary>
180192
/// Helper: Deletes every records for the given objectIDs. The `chunkedBatch` helper is used under the hood, which creates a `batch` requests with at most 1000 objectIDs in it.
181193
/// </summary>
@@ -597,6 +609,19 @@ public async Task<List<BatchResponse>> SaveObjectsAsync<T>(string indexName, IEn
597609
public List<BatchResponse> SaveObjects<T>(string indexName, IEnumerable<T> objects, bool waitForTasks = false, int batchSize = 1000, RequestOptions options = null,
598610
CancellationToken cancellationToken = default) where T : class =>
599611
AsyncHelper.RunSync(() => SaveObjectsAsync(indexName, objects, waitForTasks, batchSize, options, cancellationToken));
612+
613+
/// <inheritdoc/>
614+
public async Task<List<BatchResponse>> SaveObjectsAsync<T>(string indexName, IEnumerable<T> objects,
615+
RequestOptions options = null,
616+
CancellationToken cancellationToken = default) where T : class
617+
{
618+
return await ChunkedBatchAsync(indexName, objects, Action.AddObject, false, 1000, options, cancellationToken).ConfigureAwait(false);
619+
}
620+
621+
/// <inheritdoc/>
622+
public List<BatchResponse> SaveObjects<T>(string indexName, IEnumerable<T> objects, RequestOptions options = null,
623+
CancellationToken cancellationToken = default) where T : class =>
624+
AsyncHelper.RunSync(() => SaveObjectsAsync(indexName, objects, options, cancellationToken));
600625

601626
/// <inheritdoc/>
602627
public async Task<List<BatchResponse>> DeleteObjectsAsync(string indexName, IEnumerable<String> objectIDs,

templates/go/api.mustache

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ func WithContext(ctx context.Context) requestOption {
7171

7272
func WithHeaderParam(key string, value any) requestOption {
7373
return requestOption(func(c *config) {
74+
if c.headerParams == nil {
75+
c.headerParams = map[string]string{}
76+
}
77+
7478
c.headerParams[key] = utils.ParameterToString(value)
7579
})
7680
}
@@ -571,4 +575,4 @@ func (c *APIClient) {{nickname}}({{#hasParams}}r {{#structPrefix}}{{&classname}}
571575

572576
{{#isSearchClient}}
573577
{{> search_helpers}}
574-
{{/isSearchClient}}
578+
{{/isSearchClient}}

0 commit comments

Comments
 (0)