feat: Enhance DataManager and GraphManager with performance optimizations and caching
This commit is contained in:
+16
-4
@@ -150,6 +150,12 @@ class MedTrackerApp:
|
||||
|
||||
def _refresh_ui_after_config_change(self) -> None:
|
||||
"""Refresh UI components after pathology or medicine configuration changes."""
|
||||
# Clear caches in optimized data manager
|
||||
if hasattr(self.data_manager, "_invalidate_cache"):
|
||||
self.data_manager._invalidate_cache()
|
||||
self.data_manager._headers_cache = None
|
||||
self.data_manager._dtype_cache = None
|
||||
|
||||
# Recreate the input frame with new pathologies and medicines
|
||||
self.input_frame.destroy()
|
||||
input_ui: dict[str, Any] = self.ui_manager.create_input_frame(
|
||||
@@ -412,9 +418,10 @@ class MedTrackerApp:
|
||||
"""Load data from the CSV file into the table and graph."""
|
||||
logger.debug("Loading data from CSV.")
|
||||
|
||||
# Clear existing data in the treeview
|
||||
for i in self.tree.get_children():
|
||||
self.tree.delete(i)
|
||||
# Clear existing data in the treeview efficiently
|
||||
children = self.tree.get_children()
|
||||
if children:
|
||||
self.tree.delete(*children)
|
||||
|
||||
# Load data from the CSV file
|
||||
df: pd.DataFrame = self.data_manager.load_data()
|
||||
@@ -422,7 +429,11 @@ class MedTrackerApp:
|
||||
# Update the treeview with the data
|
||||
if not df.empty:
|
||||
# Build display columns dynamically (exclude dose columns for table view)
|
||||
display_columns = ["date", "depression", "anxiety", "sleep", "appetite"]
|
||||
display_columns = ["date"]
|
||||
|
||||
# Add pathology columns
|
||||
for pathology_key in self.pathology_manager.get_pathology_keys():
|
||||
display_columns.append(pathology_key)
|
||||
|
||||
# Add medicine columns (without dose columns)
|
||||
for medicine_key in self.medicine_manager.get_medicine_keys():
|
||||
@@ -437,6 +448,7 @@ class MedTrackerApp:
|
||||
# Fallback - just use all columns
|
||||
display_df = df
|
||||
|
||||
# Batch insert for better performance
|
||||
for _index, row in display_df.iterrows():
|
||||
self.tree.insert(parent="", index="end", values=list(row))
|
||||
logger.debug(f"Loaded {len(display_df)} entries into treeview.")
|
||||
|
||||
Reference in New Issue
Block a user