jeudi 23 juin 2016

Reduce number of SQL queries with falcor-router references

Suppose I have two falcor-routes

route: 'users[{ranges}]'

and

route: 'UserById[{integers:ids}]["name","email"]'

whereas users returns references to the UserById-route. If I then fire a query

get('users[0..10]["name","email"]')

against this, the router will first evaluate the users[0..10] part which will perform a SELECT id FROM users LIMIT 10 on the database and return the corresponding ids. The router will then use these ids together with the specific route to fill the actual values. Without akward caching on the UserService-implementation (which would need to be repeated for any similar case, e.g. addresses, cost-types and the like) this would produce at least two queries against my persistence backend, wheere a more traditional approach using a single RESTful endpoint

GET /users/?offset=0&limit=10

would most probably be content with a single one.

Is there a general best practices approach how to optimize database queries in this scenario, e.g. by some clever cache between the router and the backend services? Returning the full information already in the users route of the model is a no-go since our users might have graph links to friends which are users themselves.

Aucun commentaire:

Enregistrer un commentaire