e-mission / op-admin-dashboard

An admin/deployer dashboard for the NREL OpenPATH platform
0 stars 10 forks source link

Performance Improvements in User Stats Processing #124

Closed TeachMeTW closed 1 month ago

TeachMeTW commented 1 month ago

Description

This pull request introduces several performance improvements to the data page:

  1. Timer Integration: Added timing to measure the performance of the data page.
  2. Lazy Loading: Added processing of UUIDs in batches of 10.

Changes Made

1. Timer Integration

Added timing to measure the execution time of the add_user_stats function and other functions.

2. Lazy Loading Implementation

Replaced sequential user processing with batch processing; batches can be set in add_user_stats in db_utils for default value changes or in render_content in data.py

Each batch of 10 takes about ~7 seconds of processing.

TeachMeTW commented 1 month ago

This PR would need a squash due to my extensive commits

shankari commented 1 month ago

@JGreenlee @TeachMeTW I looked at this a while ago and came up with a plan (or two) but didn't have time to implement. The key here is to really dig into the user model and understand that the user stats consists of two separate parts:

Reading the first is super fast, because it is a single small table Reading the second is very slow because we have to essentially query for the entire trip table

We should fix this by:

shankari commented 1 month ago

Ah I think it was Patch that I originally found for lazily updating data https://plotly.com/blog/partial-properties/

TeachMeTW commented 1 month ago

@shankari I made progress in regards to the lazy loading, the only thing I'd need to figure out is how to stop it from refreshing the ui. I tried to use Patch() but seems to not work fully as intended yet; I'll keep at it.

See below:

https://github.com/user-attachments/assets/f904005c-8f83-4cbf-81a1-cd48d59b21e5

TeachMeTW commented 1 month ago

@shankari Progress, discussed with @JGreenlee to help resolve some of the issues I was facing; now loads without reloading the entire thing.

https://github.com/user-attachments/assets/bd12efa9-4dde-442f-b248-ef8a04ad4816

shankari commented 1 month ago

Squash merging this as well, make sure to pull the changes before starting on the next PR, @TeachMeTW