GreedyBear icon indicating copy to clipboard operation
GreedyBear copied to clipboard

Optimize API Performance: Remove redundant per-item serialization in `feeds_response`

Open opbot-xd opened this issue 1 week ago • 1 comments

Description

The feeds_response function in api/views/utils.py currently iterates over the IOC queryset and, for each item, instantiates a FeedsResponseSerializer to validate and serialize the data.

# api/views/utils.py

# ... inside the loop iterating over iocs ...
serializer_item = FeedsResponseSerializer(
    data=data_,
    context={"valid_feed_types": valid_feed_types},
)
serializer_item.is_valid(raise_exception=True)
json_list.append(serializer_item.data)

Problem

When the default feed_size is 5000, this loop creates 5000 individual serializer instances and performs full validation on data that was just constructed internally from our database. This adds significant overhead (CPU and time) to the response generation, making the API slower than necessary.

Proposed Solution

Since we strictly control the data_ dictionary construction immediately before this block, the data is inherently trusted. We should:

  1. Verify the data_ dictionary structure aligns with the API contract.
  2. Append data_ directly to json_list, skipping the serializer instantiation and validation entirely.

opbot-xd avatar Dec 20 '25 08:12 opbot-xd