Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache ecobenefits for a single tree #4

Open
sireliah opened this issue Jun 30, 2019 · 0 comments
Open

Cache ecobenefits for a single tree #4

sireliah opened this issue Jun 30, 2019 · 0 comments

Comments

@sireliah
Copy link
Collaborator

sireliah commented Jun 30, 2019

Overview

The /tree-benefits endpoint returns NO3, O3, PM2.5, etc. values for a single tree (based on the trunk diameter in the POST request). However we are making heavy model calculations every time we get request. We should cache the response in Redis.

Endpoint

https://github.com/kodujdlapolski/ecobenefits/blob/master/eco/server.py#L48
https://github.com/kodujdlapolski/ecobenefits#tree-benefits-endpoint

What to do

For the each request for given trunk diameter check if the result is already in Redis. If not, then use predict_tree_benefits function and store results in Redis.

Redis connection can be obtained here: https://github.com/kodujdlapolski/ecobenefits/blob/master/eco/server.py#L22. Asynchronous connection is preferred, but if there are problems, ordinary synchronous can be also used: https://github.com/kodujdlapolski/ecobenefits/blob/master/eco/utils.py#L12

It would be also nice to write some API tests for the /tree-benefits endpoint. Maybe this library can help: https://github.com/Martiusweb/asynctest. If testing of the whole endpoint is too complicated (too much to mock, async problems), then please write unit tests.

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

No branches or pull requests

1 participant