Skip to content

N+1 query in PayloadIOVBulkCreationAPIView #66

@VincenzoImp

Description

@VincenzoImp

In cdb_rest/views.py (line 446), the bulk creation endpoint resolves each PayloadList individually inside the list comprehension:

batch = [PayloadIOV(...,
                    payload_list=PayloadList.objects.get(name=obj['payload_list']),
                    ...)
         for obj in data]

For a batch of N PayloadIOVs, this executes N separate SELECT queries to resolve PayloadList names. Pre-fetching all needed PayloadList objects in a single query would reduce this to 1 query regardless of batch size.

Additionally, if a payload_list name doesn't exist, the current code raises PayloadList.DoesNotExist which surfaces as an unhandled 500. Explicit validation would return a clearer 400 response.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions