File tree Expand file tree Collapse file tree 7 files changed +20
-12
lines changed
Expand file tree Collapse file tree 7 files changed +20
-12
lines changed Original file line number Diff line number Diff line change 108108 <div class =" md:col-span-2 lg:col-span-1" >
109109 <StatCard
110110 title =" Total Heartbeats"
111- value ={adminData .total_heartbeats .toLocaleString ()}
111+ value ={` ~${ adminData .total_heartbeats .toLocaleString ()} ` }
112112 valueClass =" text-3xl font-bold text-ctp-green-600"
113113 />
114114 </div >
Original file line number Diff line number Diff line change 156156 Intl as unknown as { supportedValuesOf: (key : string ) => string [] }
157157 ).supportedValuesOf (' timeZone' );
158158 }
159- } catch {}
159+ } catch {
160+ // fallback
161+ }
160162 // fallback
161163 return [' UTC' ];
162164 };
Original file line number Diff line number Diff line change 11[package ]
22name = " rustytime-server"
33description = " 🕒 blazingly fast time tracking for developers"
4- version = " 0.16.1 "
4+ version = " 0.16.2 "
55edition = " 2024"
66authors = [" ImShyMike" ]
77readme = " ../README.md"
Original file line number Diff line number Diff line change @@ -71,30 +71,29 @@ pub async fn admin_dashboard(
7171 let offset = query. offset . max ( 0 ) ;
7272
7373 let cached = app_state. cache . admin . get ( & ( ) ) ;
74- let ( total_heartbeats , daily_activity) = if let Some ( cached) = cached {
75- ( cached. total_heartbeats , cached . daily_activity )
74+ let daily_activity = if let Some ( cached) = cached {
75+ cached. daily_activity
7676 } else {
7777 let mut conn = get_db_conn ! ( app_state) ;
7878
7979 let raw_daily_activity = db_query ! (
8080 Heartbeat :: get_daily_activity_last_week( & mut conn) ,
8181 "Failed to fetch daily activity"
8282 ) ;
83- let total_heartbeats = db_query ! ( Heartbeat :: count_total_heartbeats( & mut conn) ) ;
8483
8584 app_state. cache . admin . insert (
8685 ( ) ,
8786 CachedAdminStats {
88- total_heartbeats,
8987 daily_activity : raw_daily_activity. clone ( ) ,
9088 } ,
9189 ) ;
9290
93- ( total_heartbeats , raw_daily_activity)
91+ raw_daily_activity
9492 } ;
9593
9694 let mut conn = get_db_conn ! ( app_state) ;
9795
96+ let total_heartbeats = db_query ! ( Heartbeat :: total_heartbeat_count_estimate( & mut conn) ) ;
9897 let total_users = db_query ! ( User :: count_total_users( & mut conn, false ) ) ;
9998 let heartbeats_last_hour = db_query ! ( Heartbeat :: count_heartbeats_last_hour( & mut conn) ) ;
10099 let heartbeats_last_24h = db_query ! ( Heartbeat :: count_heartbeats_last_24h( & mut conn) ) ;
Original file line number Diff line number Diff line change @@ -182,6 +182,12 @@ pub struct UserDurationRow {
182182 pub total_seconds : i64 ,
183183}
184184
185+ #[ derive( QueryableByName ) ]
186+ struct CountRow {
187+ #[ diesel( sql_type = BigInt ) ]
188+ count : i64 ,
189+ }
190+
185191#[ derive( QueryableByName ) ]
186192struct NullableNameDurationRow {
187193 #[ diesel( sql_type = SqlNullable <Text >) ]
@@ -757,8 +763,10 @@ impl From<Heartbeat> for BulkResponseItem {
757763}
758764
759765impl Heartbeat {
760- pub fn count_total_heartbeats ( conn : & mut PgConnection ) -> QueryResult < i64 > {
761- heartbeats:: table. count ( ) . get_result ( conn)
766+ pub fn total_heartbeat_count_estimate ( conn : & mut PgConnection ) -> QueryResult < i64 > {
767+ diesel:: sql_query ( "SELECT * FROM approximate_row_count('heartbeats') AS count" )
768+ . get_result :: < CountRow > ( conn)
769+ . map ( |res| res. count )
762770 }
763771
764772 pub fn count_heartbeats_last_24h ( conn : & mut PgConnection ) -> QueryResult < i64 > {
Original file line number Diff line number Diff line change @@ -34,7 +34,6 @@ pub struct CachedLeaderboard {
3434
3535#[ derive( Clone ) ]
3636pub struct CachedAdminStats {
37- pub total_heartbeats : i64 ,
3837 pub daily_activity : Vec < DailyActivity > ,
3938}
4039
You can’t perform that action at this time.
0 commit comments