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
Slow loading /users and /assets listings #964
Comments
I endorse this idea, we need to improve loading times. In order to have a more informed process, I would like to create a script to load dummy data and perform a benchmark on this endpoint. We can try loading times with different combinations of account/users/assets. What do you think? Among the two alternatives, I would favor more (1) as it doesn't break with the status quo. |
We had the idea for a benchmark script here but didn't find the right underlying approach yet. |
Thanks for the reference! #949 apparently benchmarks fetching data from the DB (via calling show beliefs command). I was planning to create something that actually hit the endpoint to see the response time. What do you think? |
I agree the approach needs not to call CLI commands, also due to their initial loading time. I thought about calling code directly (and first establishing an app context), then we can call whatever function we like. But probably simply using the API might be more straightforward. |
I have create a WIP PR to speed up the loading times of the Benchmark scriptimport requests
from bs4 import BeautifulSoup
import time
session = requests.Session()
session.max_redirects = 3
# get CSRF Token
response = session.get("http://localhost:5000")
soup = BeautifulSoup(response.text, "html.parser")
csrf_token = soup.find("input", {"id" : "csrf_token"})["value"]
## Login
response = session.post(
"http://localhost:5000/login",
data={
"email" : "<email>",
"password" : "<password>",
"submit" : "Login",
"next" : "",
"csrf_token" : csrf_token
},
)
for _ in range(10):
t = time.time()
response = session.get("http://localhost:5000/assets")
print(time.time() - t)
soup = BeautifulSoup(response.text, "html.parser")
print(soup.title.get_text()) # we should see Asset listing - FlexMeasures |
I'm noticing the
/users
(and the/assets
) page can take seconds to load if there are many organisation accounts. Internally, the/api/v3_0/users?account_id=<id>
endpoint is getting called as many times as there are organisation accounts that the user has access to, so there is great potential to speed this up. Two options that come to mind:account_id
multiple times to the users listing endpoint, so we only need to call it once. This would probably require thepermission_required_for_context
decorator to be enhanced to support a list of accounts.users += get_users_by_account(account.id, include_inactive)
(which uses theInternalAPI
), useusers += account.users
and then filter out the inactive users if needed.Arguably, option 2 is easier to implement, but option 1 actually improves API and auth capabilities.
The text was updated successfully, but these errors were encountered: