Skip to content

Commit e0f7692

Browse files
committed
chore: ruby
1 parent 309a683 commit e0f7692

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

templates/ruby/search_helpers.mustache

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,17 +212,18 @@ end
212212
# @param index_name [String]: The `index_name` to save `objects` in.
213213
# @param objects [Array]: The array of `objects` to store in the given Algolia `indexName`.
214214
# @param wait_for_tasks [Boolean]: Whether or not we should wait until every `batch` tasks has been processed, this operation may slow the total execution time of this method but is more reliable.
215+
# @param batch_size [int] The size of the chunk of `objects`. The number of `batch` calls will be equal to `length(objects) / batchSize`. Defaults to 1000.
215216
# @param request_options: The request options to send along with the query, they will be merged with the transporter base parameters (headers, query params, timeouts, etc.). (optional)
216217
#
217218
# @return [BatchResponse]
218219
#
219-
def save_objects(index_name, objects, wait_for_tasks = false, request_options = {})
220+
def save_objects(index_name, objects, wait_for_tasks = false, batch_size = 1000, request_options = {})
220221
chunked_batch(
221222
index_name,
222223
objects,
223224
Search::Action::ADD_OBJECT,
224225
wait_for_tasks,
225-
1000,
226+
batch_size,
226227
request_options
227228
)
228229
end
@@ -232,17 +233,18 @@ end
232233
# @param index_name [String]: The `index_name` to delete `object_ids` from.
233234
# @param object_ids [Array]: The object_ids to delete.
234235
# @param wait_for_tasks [Boolean]: Whether or not we should wait until every `batch` tasks has been processed, this operation may slow the total execution time of this method but is more reliable.
236+
# @param batch_size [int] The size of the chunk of `objects`. The number of `batch` calls will be equal to `length(objects) / batchSize`. Defaults to 1000.
235237
# @param request_options: The request options to send along with the query, they will be merged with the transporter base parameters (headers, query params, timeouts, etc.). (optional)
236238
#
237239
# @return [BatchResponse]
238240
#
239-
def delete_objects(index_name, object_ids, wait_for_tasks = false, request_options = {})
241+
def delete_objects(index_name, object_ids, wait_for_tasks = false, batch_size = 1000, request_options = {})
240242
chunked_batch(
241243
index_name,
242244
object_ids.map { |id| { "objectID" => id } },
243245
Search::Action::DELETE_OBJECT,
244246
wait_for_tasks,
245-
1000,
247+
batch_size,
246248
request_options
247249
)
248250
end
@@ -253,17 +255,18 @@ end
253255
# @param objects [Array]: The objects to partially update.
254256
# @param create_if_not_exists [Boolean]: To be provided if non-existing objects are passed, otherwise, the call will fail.
255257
# @param wait_for_tasks [Boolean] Whether or not we should wait until every `batch` tasks has been processed, this operation may slow the total execution time of this method but is more reliable.
258+
# @param batch_size [int] The size of the chunk of `objects`. The number of `batch` calls will be equal to `length(objects) / batchSize`. Defaults to 1000.
256259
# @param request_options: The request options to send along with the query, they will be merged with the transporter base parameters (headers, query params, timeouts, etc.). (optional)
257260
#
258261
# @return [BatchResponse]
259262
#
260-
def partial_update_objects(index_name, objects, create_if_not_exists, wait_for_tasks = false, request_options = {})
263+
def partial_update_objects(index_name, objects, create_if_not_exists, wait_for_tasks = false, batch_size = 1000, request_options = {})
261264
chunked_batch(
262265
index_name,
263266
objects,
264267
create_if_not_exists ? Search::Action::PARTIAL_UPDATE_OBJECT : Search::Action::PARTIAL_UPDATE_OBJECT_NO_CREATE,
265268
wait_for_tasks,
266-
1000,
269+
batch_size,
267270
request_options
268271
)
269272
end

0 commit comments

Comments
 (0)