INNER CODE UNIT · Python

record_size

defiprime/defiprime1 · scripts/algolia-index.py:34

def record_size(record):
    return len(encode_record(record))


def load_records(path):
    with open(path, encoding="utf-8") as handle:
        payload = json.load(handle)
    if not isinstance(payload, list):
        raise ValueError(f"{path}: expected a JSON list of records")
    seen = set()
    for position, record in enumerate(payload):
        if not isinstance(record, dict):
            raise ValueError(f"{path}: record {position} is not an object")
        object_id = record.get("objectID")
        if not object_id:
            raise ValueError(f"{path}: record {position} has no objectID")
        if object_id in seen:
            raise ValueError(f"{path}: duplicate objectID {object_id!r}")

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…