@@ -89,18 +89,35 @@ public function index()
8989 //
9090 $ this ->load ->model ('cat ' );
9191 $ this ->load ->model ('vucc ' );
92+
93+ // Load cache driver for dashboard statistics caching (15 minutes)
94+ $ this ->load ->driver ('cache ' , array ('adapter ' => 'file ' ));
9295
9396 $ data ['radio_status ' ] = $ this ->cat ->recent_status ();
9497
95- // Store info - Use consolidated query for QSO statistics
96- $ qso_stats = $ this ->logbook_model ->get_qso_statistics_consolidated ($ logbooks_locations_array );
98+ // Create cache key based on user and active logbook
99+ $ cache_key = 'dashboard_stats_ ' . $ this ->session ->userdata ('user_id ' ) . '_ ' . $ this ->session ->userdata ('active_station_logbook ' );
100+ $ cache_ttl = 900 ; // 15 minutes
101+
102+ // Try to get QSO statistics from cache
103+ $ qso_stats = $ this ->cache ->get ($ cache_key . '_qso ' );
104+ if (!$ qso_stats ) {
105+ // Cache miss - query database
106+ $ qso_stats = $ this ->logbook_model ->get_qso_statistics_consolidated ($ logbooks_locations_array );
107+ $ this ->cache ->save ($ cache_key . '_qso ' , $ qso_stats , $ cache_ttl );
108+ }
97109 $ data ['todays_qsos ' ] = $ qso_stats ['todays_qsos ' ];
98110 $ data ['total_qsos ' ] = $ qso_stats ['total_qsos ' ];
99111 $ data ['month_qsos ' ] = $ qso_stats ['month_qsos ' ];
100112 $ data ['year_qsos ' ] = $ qso_stats ['year_qsos ' ];
101113
102- // Use consolidated countries statistics instead of separate queries
103- $ countries_stats = $ this ->logbook_model ->get_countries_statistics_consolidated ($ logbooks_locations_array );
114+ // Try to get countries statistics from cache
115+ $ countries_stats = $ this ->cache ->get ($ cache_key . '_countries ' );
116+ if (!$ countries_stats ) {
117+ // Cache miss - query database
118+ $ countries_stats = $ this ->logbook_model ->get_countries_statistics_consolidated ($ logbooks_locations_array );
119+ $ this ->cache ->save ($ cache_key . '_countries ' , $ countries_stats , $ cache_ttl );
120+ }
104121
105122 $ data ['total_countries ' ] = $ countries_stats ['Countries_Worked ' ];
106123 $ data ['total_countries_confirmed_paper ' ] = $ countries_stats ['Countries_Worked_QSL ' ];
@@ -131,12 +148,27 @@ public function index()
131148
132149 // Only load VUCC data if the card is actually enabled
133150 if ($ data ['dashboard_vuccgrids_card ' ]) {
134- $ data ['vucc ' ] = $ this ->vucc ->fetchVuccSummary ();
135- $ data ['vuccSAT ' ] = $ this ->vucc ->fetchVuccSummary ('SAT ' );
151+ // Try to get VUCC data from cache
152+ $ vucc_data = $ this ->cache ->get ($ cache_key . '_vucc ' );
153+ if (!$ vucc_data ) {
154+ // Cache miss - query database
155+ $ vucc_data = array (
156+ 'vucc ' => $ this ->vucc ->fetchVuccSummary (),
157+ 'vuccSAT ' => $ this ->vucc ->fetchVuccSummary ('SAT ' )
158+ );
159+ $ this ->cache ->save ($ cache_key . '_vucc ' , $ vucc_data , $ cache_ttl );
160+ }
161+ $ data ['vucc ' ] = $ vucc_data ['vucc ' ];
162+ $ data ['vuccSAT ' ] = $ vucc_data ['vuccSAT ' ];
136163 }
137164
138-
139- $ QSLStatsBreakdownArray = $ this ->logbook_model ->get_QSLStats ($ logbooks_locations_array );
165+ // Try to get QSL statistics from cache
166+ $ QSLStatsBreakdownArray = $ this ->cache ->get ($ cache_key . '_qsl ' );
167+ if (!$ QSLStatsBreakdownArray ) {
168+ // Cache miss - query database
169+ $ QSLStatsBreakdownArray = $ this ->logbook_model ->get_QSLStats ($ logbooks_locations_array );
170+ $ this ->cache ->save ($ cache_key . '_qsl ' , $ QSLStatsBreakdownArray , $ cache_ttl );
171+ }
140172
141173 $ data ['total_qsl_sent ' ] = $ QSLStatsBreakdownArray ['QSL_Sent ' ];
142174 $ data ['total_qsl_rcvd ' ] = $ QSLStatsBreakdownArray ['QSL_Received ' ];
0 commit comments