Fix issue with n+1 API calls on device/owners#2
Draft
pelted wants to merge 1 commit into
Draft
Conversation
…f device and person data. This improves performance by batching requests and reduces the need for sequential API calls. Update records in-place with owner_name and owner_email fields based on fetched data. For 100 unique devices owned by 100 unique people, this goes from ~200 sequential round-trips to 2 concurrent batches.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Changed
Before: The loop iterated through every record, issuing up to 2 await calls per unique device — fully sequential. 100 unique devices = up to 200 serial API calls.
After: Two batched concurrent rounds:
asyncio.gatherto fetch all/devices/{id}concurrently.asyncio.gatherto fetch all/people/{id}concurrently.The
asyncio.Semaphore(10)caps concurrency to, at most, 10 API requests in-flight at a time to avoid hammering the Kolide API.For 100 unique devices owned by 100 unique people, this goes from ~200 sequential round-trips to 2 concurrent batches — a dramatic improvement.