@@ -15,6 +15,7 @@ let huntarrUI = {
1515 currentLogApp : 'all' , // Default log app
1616 currentHistoryApp : 'all' , // Default history app
1717 autoScroll : true ,
18+ isLoadingStats : false , // Flag to prevent multiple simultaneous stats requests
1819 configuredApps : {
1920 sonarr : false ,
2021 radarr : false ,
@@ -87,7 +88,7 @@ let huntarrUI = {
8788 this . logoUrl = localStorage . getItem ( 'huntarr-logo-url' ) || this . logoUrl ;
8889
8990 // Load media stats
90- this . loadMediaStats ( ) ; // Load media statistics
91+ // this.loadMediaStats(); // Load media statistics
9192
9293 // Load current version
9394 this . loadCurrentVersion ( ) ; // Load current version
@@ -611,8 +612,8 @@ let huntarrUI = {
611612 this . disconnectAllEventSources ( ) ;
612613 // Check app connections when returning to home page to update status
613614 this . checkAppConnections ( ) ;
614- // Also refresh media stats
615- this . loadMediaStats ( ) ;
615+ // Stats are already loaded, no need to reload unless data changed
616+ // this.loadMediaStats();
616617 } else if ( section === 'logs' && this . elements . logsSection ) {
617618 this . elements . logsSection . classList . add ( 'active' ) ;
618619 this . elements . logsSection . style . display = 'block' ;
@@ -2115,11 +2116,20 @@ let huntarrUI = {
21152116
21162117 // Media statistics handling
21172118 loadMediaStats : function ( ) {
2119+ // Prevent multiple simultaneous stats loading
2120+ if ( this . isLoadingStats ) {
2121+ console . debug ( 'Stats already loading, skipping duplicate request' ) ;
2122+ return ;
2123+ }
2124+
2125+ this . isLoadingStats = true ;
2126+
21182127 // Add loading class to stats container to hide raw JSON
21192128 const statsContainer = document . querySelector ( '.media-stats-container' ) ;
21202129 if ( statsContainer ) {
21212130 statsContainer . classList . add ( 'stats-loading' ) ;
21222131 }
2132+
21232133 HuntarrUtils . fetchWithTimeout ( '/api/stats' )
21242134 . then ( response => {
21252135 if ( ! response . ok ) {
@@ -2136,7 +2146,6 @@ let huntarrUI = {
21362146 this . updateStatsDisplay ( data . stats ) ;
21372147
21382148 // Remove loading class after stats are loaded
2139- const statsContainer = document . querySelector ( '.media-stats-container' ) ;
21402149 if ( statsContainer ) {
21412150 statsContainer . classList . remove ( 'stats-loading' ) ;
21422151 }
@@ -2146,6 +2155,14 @@ let huntarrUI = {
21462155 } )
21472156 . catch ( error => {
21482157 console . error ( 'Error fetching statistics:' , error ) ;
2158+ // Remove loading class on error too
2159+ if ( statsContainer ) {
2160+ statsContainer . classList . remove ( 'stats-loading' ) ;
2161+ }
2162+ } )
2163+ . finally ( ( ) => {
2164+ // Always clear the loading flag
2165+ this . isLoadingStats = false ;
21492166 } ) ;
21502167 } ,
21512168
@@ -2879,7 +2896,7 @@ let huntarrUI = {
28792896 console . log ( '[huntarrUI] Stateful expiration updated successfully:' , data ) ;
28802897
28812898 // Get updated info to show proper dates
2882- this . loadStatefulInfo ( 0 , true ) ;
2899+ this . loadStatefulInfo ( ) ;
28832900
28842901 // Show a notification
28852902 this . showNotification ( `Updated expiration to ${ hours } hours (${ ( hours / 24 ) . toFixed ( 1 ) } days)` , 'success' ) ;
0 commit comments