Skip to content

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 🏆 Team Leaderboard module, the entire Workspace was reloading.

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

  1. Execution Locking

    • Introduced _lb_has_run flag to track whether analysis has been executed.
  2. Result Caching

    • Stored computed batch results in:
      st.session_state["_lb_cached_results"]
  3. Filter Freezing

    • Frozen filter values stored in:
      st.session_state["_lb_frozen_filters"]
    • Prevents live date re-evaluation on page switch.
  4. 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" Yes
Switch Workspace → Ranking No
Switch Ranking → Workspace No
Change filters without clicking Run No
Click Run again Yes

📈 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.py modified
  • No changes to:
    • batch.py
    • issues.py
    • commits.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.

Merge request reports

Loading