1+ use std:: time:: { SystemTime , UNIX_EPOCH } ;
2+ use rand:: Rng ;
13use serde_json:: { json, Value } ;
24use std:: { sync:: { Arc , Mutex as SyncMutex } , time:: Duration } ;
35use time:: { format_description:: well_known:: Rfc3339 , OffsetDateTime } ;
4- use uuid:: Uuid ;
56
67use crate :: {
78 config:: Config ,
@@ -10,6 +11,20 @@ use crate::{
1011
1112static SESSION_TIMEOUT : Duration = Duration :: from_secs ( 4 * 60 * 60 ) ;
1213
14+ fn new_session_id ( ) -> String {
15+ let epoch_in_seconds = SystemTime :: now ( )
16+ . duration_since ( UNIX_EPOCH )
17+ . expect ( "time went backwards" )
18+ . as_secs ( ) ;
19+
20+ let mut rng = rand:: thread_rng ( ) ;
21+ let random: u64 = rng. gen_range ( 0 ..=99999999 ) ;
22+
23+ let id = epoch_in_seconds * 100_000_000 + random;
24+
25+ return id. to_string ( ) ;
26+ }
27+
1328/// A tracking session.
1429#[ derive( Debug , Clone ) ]
1530pub struct TrackingSession {
@@ -20,7 +35,7 @@ pub struct TrackingSession {
2035impl TrackingSession {
2136 fn new ( ) -> Self {
2237 TrackingSession {
23- id : Uuid :: new_v4 ( ) . to_string ( ) ,
38+ id : new_session_id ( ) ,
2439 last_touch_ts : OffsetDateTime :: now_utc ( ) ,
2540 }
2641 }
@@ -52,7 +67,7 @@ impl AptabaseClient {
5267 sys_info,
5368 }
5469 }
55-
70+
5671 /// Starts the event dispatcher loop.
5772 pub ( crate ) fn start_polling ( & self , interval : Duration ) {
5873 let dispatcher = self . dispatcher . clone ( ) ;
0 commit comments