Skip to content

Add request batching - #402

Merged
JSReds merged 1 commit into
masterfrom
feature/add-request-batching
Jul 2, 2026
Merged

Add request batching#402
JSReds merged 1 commit into
masterfrom
feature/add-request-batching

Conversation

@JSReds

@JSReds JSReds commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

See: https://balena.fibery.io/Work/Project/Add-batch-operation-handler-in-Python-SDK-2489

Change-type: minor

Description:

Introduce batch_resource_operation_factory to resolve, chunk, and validate lists of UUIDs/IDs before executing an operation (200 numeric / 50 string per chunk). Wire it into device.move, pin_to_release, pin_to_supervisor_release, and application.remove, which now all accept arrays in addition to a single uuid/id.

@JSReds JSReds self-assigned this Jun 18, 2026
@JSReds
JSReds requested a review from otaviojacobi June 18, 2026 10:42
@JSReds
JSReds force-pushed the feature/add-request-batching branch from 2bf9131 to fd79ef9 Compare June 18, 2026 10:49
@JSReds
JSReds removed the request for review from otaviojacobi June 18, 2026 11:18
@JSReds
JSReds force-pushed the feature/add-request-batching branch 5 times, most recently from 6daae66 to 59da410 Compare June 18, 2026 18:55
@JSReds
JSReds requested a review from otaviojacobi June 18, 2026 19:32
Comment thread balena/utils/__init__.py Outdated
@JSReds
JSReds requested a review from otaviojacobi June 22, 2026 10:32
@JSReds
JSReds force-pushed the feature/add-request-batching branch from fdc3d3f to b37c185 Compare June 22, 2026 15:50
Comment thread balena/models/application.py Outdated

Args:
slug_or_uuid_or_id (Union[str, int]): application slug (string), uuid (string) or id (number).
slug_or_uuid_or_id (Union[str, int, List[int]]): application slug (string), uuid (string),

@otaviojacobi otaviojacobi Jun 23, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slug_or_uuid_or_id_or_ids?
It is very long but at least it is consistent with the other ones....

Comment thread balena/models/application.py Outdated
"""

try:
if isinstance(slug_or_uuid_or_id, str):

@otaviojacobi otaviojacobi Jun 23, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a bug isn't it? This path should also be taken if slug_or_uuid_or_id is a single id (number), otherwise this will "work" but it gets compiled into a $in filter with a single element, which at SQL levl is less efficient than indexing directly by its id (it becomes a = ANY() with a binding param so it creates a full list and maybe be harder for the api to cache aswell)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More over, have you checked that ApplicationNotFound is still raised properly? I suspect yes, but it would be good to check if the tests cover it

Comment thread balena/models/device.py Outdated
query["body"] = body
actual_fn(query)

self.__batch_device_operation(uuid_or_id_or_ids, _operation)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think same comment as above? Ideally, if we get just a single uuid or single id, we prefer to use the resource_id indexing (e.g. directly passing an ID or {"uuid"...}, is the node-sdk also generalising over batch operations even when a single one is passing? 🤔

@JSReds
JSReds force-pushed the feature/add-request-batching branch 6 times, most recently from c5721bb to 5546877 Compare June 24, 2026 17:33
Comment thread balena/models/device.py
Comment on lines +690 to 698
{
"$select": "id",
"$expand": {
"is_for__device_type": {
"$select": "is_of__cpu_architecture",
"$expand": {"is_of__cpu_architecture": {"$select": "slug"}},
}
},
},

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I usually prefer to not create a variable if the query is small but if you prefer to keep the options separated I can revert it without issues

@JSReds
JSReds force-pushed the feature/add-request-batching branch from d0b6145 to 4f6a1f5 Compare June 25, 2026 07:40
@JSReds
JSReds requested a review from otaviojacobi June 25, 2026 07:59
@JSReds
JSReds force-pushed the feature/add-request-batching branch from 4f6a1f5 to 37f1df8 Compare July 2, 2026 10:49
@JSReds
JSReds force-pushed the feature/add-request-batching branch from 37f1df8 to eb07602 Compare July 2, 2026 10:52
@JSReds
JSReds marked this pull request as ready for review July 2, 2026 11:17
@JSReds
JSReds merged commit e6b2f97 into master Jul 2, 2026
56 checks passed
@JSReds
JSReds deleted the feature/add-request-batching branch July 2, 2026 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants