11use crate :: error:: { ModuleReloadError , RariError } ;
22use crate :: rsc:: components:: ComponentRegistry ;
33use crate :: runtime:: JsExecutionRuntime ;
4- use crate :: runtime:: module_reload:: {
5- DebounceManager , ModuleReloadRequest , ReloadConfig , ReloadHistoryEntry , ReloadStats ,
6- } ;
4+ use crate :: runtime:: module_reload:: { DebounceManager , ModuleReloadRequest , ReloadConfig } ;
75use crate :: runtime:: utils:: DistPathResolver ;
86use std:: collections:: VecDeque ;
97use std:: path:: Path ;
108use std:: sync:: Arc ;
11- use std:: time:: { Duration , Instant } ;
12- use tokio:: sync:: { Mutex , RwLock } ;
9+ use std:: time:: Duration ;
10+ use tokio:: sync:: Mutex ;
1311use tracing:: error;
1412
1513pub struct ModuleReloadManager {
1614 reload_queue : Arc < Mutex < VecDeque < ModuleReloadRequest > > > ,
17- reload_stats : Arc < RwLock < ReloadStats > > ,
1815 config : ReloadConfig ,
1916 runtime : Option < Arc < JsExecutionRuntime > > ,
2017 component_registry : Option < Arc < parking_lot:: Mutex < ComponentRegistry > > > ,
2118 debounce_manager : DebounceManager ,
22- reload_history : Arc < Mutex < VecDeque < ReloadHistoryEntry > > > ,
2319 dist_path_resolver : Option < Arc < DistPathResolver > > ,
2420}
2521
2622impl Clone for ModuleReloadManager {
2723 fn clone ( & self ) -> Self {
2824 Self {
2925 reload_queue : Arc :: clone ( & self . reload_queue ) ,
30- reload_stats : Arc :: clone ( & self . reload_stats ) ,
3126 config : self . config . clone ( ) ,
3227 runtime : self . runtime . clone ( ) ,
3328 component_registry : self . component_registry . clone ( ) ,
3429 debounce_manager : self . debounce_manager . clone ( ) ,
35- reload_history : Arc :: clone ( & self . reload_history ) ,
3630 dist_path_resolver : self . dist_path_resolver . clone ( ) ,
3731 }
3832 }
@@ -42,25 +36,21 @@ impl ModuleReloadManager {
4236 pub fn new ( config : ReloadConfig ) -> Self {
4337 Self {
4438 reload_queue : Arc :: new ( Mutex :: new ( VecDeque :: new ( ) ) ) ,
45- reload_stats : Arc :: new ( RwLock :: new ( ReloadStats :: default ( ) ) ) ,
4639 config,
4740 runtime : None ,
4841 component_registry : None ,
4942 debounce_manager : DebounceManager :: new ( ) ,
50- reload_history : Arc :: new ( Mutex :: new ( VecDeque :: new ( ) ) ) ,
5143 dist_path_resolver : None ,
5244 }
5345 }
5446
5547 pub fn with_runtime ( config : ReloadConfig , runtime : Arc < JsExecutionRuntime > ) -> Self {
5648 Self {
5749 reload_queue : Arc :: new ( Mutex :: new ( VecDeque :: new ( ) ) ) ,
58- reload_stats : Arc :: new ( RwLock :: new ( ReloadStats :: default ( ) ) ) ,
5950 config,
6051 runtime : Some ( runtime) ,
6152 component_registry : None ,
6253 debounce_manager : DebounceManager :: new ( ) ,
63- reload_history : Arc :: new ( Mutex :: new ( VecDeque :: new ( ) ) ) ,
6454 dist_path_resolver : None ,
6555 }
6656 }
@@ -89,10 +79,6 @@ impl ModuleReloadManager {
8979 self . config . enabled
9080 }
9181
92- pub async fn get_stats ( & self ) -> ReloadStats {
93- self . reload_stats . read ( ) . await . clone ( )
94- }
95-
9682 pub async fn enqueue_reload ( & self , request : ModuleReloadRequest ) {
9783 let mut queue = self . reload_queue . lock ( ) . await ;
9884 queue. push_back ( request) ;
@@ -116,37 +102,6 @@ impl ModuleReloadManager {
116102 fn clone_for_task ( & self ) -> Self {
117103 self . clone ( )
118104 }
119-
120- async fn record_reload_stats ( & self , success : bool , duration_ms : u64 ) {
121- let mut stats = self . reload_stats . write ( ) . await ;
122- stats. record_reload ( success, duration_ms) ;
123- }
124-
125- async fn add_to_history ( & self , component_id : String , success : bool , duration_ms : u64 ) {
126- let mut history = self . reload_history . lock ( ) . await ;
127-
128- let entry = ReloadHistoryEntry :: new ( component_id, success, duration_ms) ;
129- history. push_back ( entry) ;
130-
131- while history. len ( ) > self . config . max_history_size {
132- history. pop_front ( ) ;
133- }
134- }
135-
136- pub async fn get_reload_history ( & self ) -> Vec < ReloadHistoryEntry > {
137- let history = self . reload_history . lock ( ) . await ;
138- history. iter ( ) . cloned ( ) . collect ( )
139- }
140-
141- pub async fn clear_history ( & self ) {
142- let mut history = self . reload_history . lock ( ) . await ;
143- history. clear ( ) ;
144- }
145-
146- pub async fn get_memory_usage ( & self ) -> u64 {
147- let stats = self . reload_stats . read ( ) . await ;
148- stats. estimated_memory_bytes
149- }
150105}
151106
152107impl ModuleReloadManager {
@@ -192,15 +147,8 @@ impl ModuleReloadManager {
192147 return Ok ( ( ) ) ;
193148 }
194149
195- let start = Instant :: now ( ) ;
196-
197150 let result = self . reload_with_retry ( component_id, file_path) . await ;
198151
199- let duration_ms = start. elapsed ( ) . as_millis ( ) as u64 ;
200-
201- self . record_reload_stats ( result. is_ok ( ) , duration_ms) . await ;
202- self . add_to_history ( component_id. to_string ( ) , result. is_ok ( ) , duration_ms) . await ;
203-
204152 match & result {
205153 Ok ( _) => { }
206154 Err ( e) => {
0 commit comments