INNER CODE UNIT · Python
batch_records
defiprime/defiprime1 · scripts/algolia-index.py:82
def batch_records(records, max_bytes, max_records):
batches = []
current = []
current_bytes = 0
for record in records:
size = record_size(record)
if current and (
len(current) >= max_records or current_bytes + size > max_bytes
):
batches.append(current)
current = []
current_bytes = 0
current.append(record)
current_bytes += size
if current:
batches.append(current)
return batches