Skip to content

Commit a5c7a5c

Browse files
committed
feat: prevent saving if log files is too big
1 parent 0c917a9 commit a5c7a5c

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/app.rs

+19-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ pub struct LogViewerApp {
3333
should_scroll_to_end_on_load: bool,
3434
/// Allows the user to dim the warning by clicking on it
3535
should_highlight_field_warning: bool,
36+
/// Max size in bytes of data before saving is disabled
37+
max_data_save_size: Option<usize>,
3638

3739
#[serde(skip)]
3840
should_focus_search: bool,
@@ -60,6 +62,7 @@ impl Default for LogViewerApp {
6062
should_scroll: Default::default(),
6163
show_last_filename: true,
6264
last_save_hash: Default::default(),
65+
max_data_save_size: Some(2 * 1024 * 1024), // 2 MB
6366
}
6467
}
6568
}
@@ -771,6 +774,20 @@ impl LogViewerApp {
771774
self.last_save_hash = Some(new_hash);
772775
true
773776
}
777+
778+
fn should_save(&mut self) -> bool {
779+
// Check if size of data allows saving
780+
if let (Some(data), Some(max_data_size)) =
781+
(self.data.as_ref(), self.max_data_save_size.as_ref())
782+
{
783+
if &data.file_size_as_bytes > max_data_size {
784+
return false;
785+
}
786+
}
787+
788+
// Size of data does not prevent saving, check if there are changes to be saved
789+
self.is_changed_since_last_save()
790+
}
774791
}
775792

776793
#[cfg(not(target_arch = "wasm32"))]
@@ -820,13 +837,13 @@ impl eframe::App for LogViewerApp {
820837
fn save(&mut self, storage: &mut dyn eframe::Storage) {
821838
#[cfg(feature = "profiling")]
822839
puffin::profile_scope!("eframe::App::save");
823-
if self.is_changed_since_last_save() {
840+
if self.should_save() {
824841
info!("Saving data");
825842
#[cfg(feature = "profiling")]
826843
puffin::profile_scope!("Saving App State");
827844
eframe::set_value(storage, eframe::APP_KEY, self);
828845
} else {
829-
debug!("Save skipped, no change detected");
846+
debug!("Save skipped");
830847
}
831848
}
832849

0 commit comments

Comments
 (0)