Skip to content

Conversation

@lampwins
Copy link
Contributor

Fixes: #4559

This implements a new queryset manager for the device and virtual machine models which includes an annotate_config_context_data() method. This method uses a dynamically generated subquery with the JSONBAgg function to annotate the list of config context json objects directly on the device and virtual machine querysets.

There are a couple of things to note:

  • Django has included the postgres JSONBAgg function for a while but in 3.2 it includes support for aggregation ordering. My implementation includes a custom subclass which implements the same until we move to 3.2. Ordering is a critical component of being able to do this as a subquery.
  • The original get_for_object() method is still present and actively used. This is still needed to query for the actual ConfigContext instances for a given object, and in certain cases where the annotation is not available.
  • Because the annotation method is optional and not added to the queryset by default, the existing ability to exclude config context data from the API response is still in place.

Copy link
Member

@jeremystretch jeremystretch left a comment

Choose a reason for hiding this comment

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

Great work! And yes, much faster. Just had a couple minor points. If you don't feel the need to act on either, I'm fine with merging this as-is. 👍

@jeremystretch jeremystretch merged commit 04d763d into develop Oct 30, 2020
@jeremystretch jeremystretch deleted the 4559-config-context-rendering branch October 30, 2020 13:09
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve Performance of Generating Config Contexts

3 participants