Open dgarros opened 1 year ago
As a first step I think we should extend the InfrahubDatabase
Class to include a cache (AKA DataLoader) this way, if a query is trying to access the same object multiple times it would be served from the cache after the initial retrieval.
Graphene recommandation is to use the dataloader library.
https://docs.graphene-python.org/en/latest/execution/dataloader/
To avoid managing cache invalidation, a new cache could be created per session/request which fits very well with the lifespan of the InfrahubDatabase
object itself.
The functions get_one
and get_many
in the NodeManager are good candidates to implement the cache
Component
API Server / GraphQL
Describe the Feature Request
Currently the GraphQL API isn't really fast and while there are many things to consider (see #440), one of the main reason is the code of the GraphQL resolver hasn't been optimized yet.
As a reference point, today to query 100 BGP Sessions we are making ~1400 queries to the database which means we are making on average 14 queries per objects. With some optimization we should be able to reduce this number by 5x to 10x.
Describe the Use Case
Improve the response time of the GraphQL API
Additional Information
No response