fix: page reloading again and again when we move between pages it only reloads...
🚀 Fix: Prevent Unnecessary Reload When Switching Leaderboard Pages
🧩 Problem
When switching between Workspace and Leaderboard Ranking in the
Specifically:
- Date filters were re-evaluated
- Batch processing re-executed
- API calls were triggered again
- Team results were recomputed
- UI re-rendered fully
This behavior occurred because Streamlit reruns the script on every widget interaction (including radio button page switches). Since batch execution logic depended directly on live filter values, it was unintentionally re-triggered during navigation.
This resulted in:
- Unnecessary API calls
- Performance overhead
- Slower UI experience
- Redundant data fetching
🎯 Objective
Ensure that:
- Batch processing runs only when "Run Leaderboard Analysis" is clicked
- Switching between Workspace and Leaderboard Ranking does not trigger recomputation
- Date filters are frozen until the next manual run
- No other functionality is changed
- No backend logic is modified
- No other files are touched
✅ Solution Implemented
A controlled execution flow was introduced using st.session_state inside team_leaderboard.py.
🔒 Key Improvements
-
Execution Locking
- Introduced
_lb_has_runflag to track whether analysis has been executed.
- Introduced
-
Result Caching
- Stored computed batch results in:
st.session_state["_lb_cached_results"]
- Stored computed batch results in:
-
Filter Freezing
- Frozen filter values stored in:
st.session_state["_lb_frozen_filters"] - Prevents live date re-evaluation on page switch.
- Frozen filter values stored in:
-
Controlled Re-execution
- Batch logic now runs only inside Run button block
- Page switches reuse cached results instead of recomputing
🧠 Resulting Behavior
| Action | Batch Re-Executed? |
|---|---|
| Click "Run Leaderboard Analysis" |
|
| Switch Workspace → Ranking |
|
| Switch Ranking → Workspace |
|
| Change filters without clicking Run |
|
| Click Run again |
|
📈 Impact
- Eliminated unnecessary API calls
- Improved performance and responsiveness
- Reduced redundant computation
- Maintained full backward compatibility
- Preserved scoring, filters, and architecture
- No changes outside
team_leaderboard.py
🔐 Scope
- Only
team_leaderboard.pymodified - No changes to:
batch.pyissues.pycommits.py- Scoring logic
- Filter logic
- Data structure
- Architecture
🏁 Final Outcome
The Team Leaderboard module now behaves like a proper production dashboard:
- Deterministic execution
- Controlled recomputation
- Stable page navigation
- Efficient API usage
This significantly improves usability and performance while keeping all existing functionality intact.