From da5d2a9673591e44b2f4b203b214e11f394244c4 Mon Sep 17 00:00:00 2001 From: user Date: Thu, 30 May 2024 10:59:23 +0200 Subject: [PATCH] Create module for migration logic, add `GpuJson` migration logic --- backend/src/persist/migration.rs | 70 +---------------------- backend/src/persist/migration/gpu.rs | 26 +++++++++ backend/src/persist/migration/settings.rs | 58 +++++++++++++++++++ backend/src/persist/mod.rs | 2 +- 4 files changed, 87 insertions(+), 69 deletions(-) create mode 100644 backend/src/persist/migration/gpu.rs create mode 100644 backend/src/persist/migration/settings.rs diff --git a/backend/src/persist/migration.rs b/backend/src/persist/migration.rs index 88122f4..37c3f2e 100644 --- a/backend/src/persist/migration.rs +++ b/backend/src/persist/migration.rs @@ -1,68 +1,2 @@ -// - Commit that changed setting format: 3aa9680baedf850d7d576d0df28ce50cf2124ebe. -// - Commit that made settings variant use u64 instead of String: -// d481f1314409c99a0ed48b006a8e9b53f6caa8a5. -// - Add all back-end functionality for interacting with variants on the front-end: -// 4eaf6fae2bba0219a316d37499ee6e1549645862. -// - Improve memory clock selection for #140, fix dpm_performance enforcement check for GPU: -// a1c44cdea7ae27f7a09fd194c580c79b291d25d1. -// - Remove legacy charge mode and level functionality: 88d359e286bec2fdabde0f4f72b52fb8f4d5200e. -// - Add tags for persistent settings variants: ccf0c04020bfc5ae9f667801f99d1a31f939006a. - -// TODO: Check full git diff between data structures from version 1.4.0 and current, to see exactly -// what changed and how to migrate them to the current data structures. - -use std::collections::HashMap; - -use serde::{Deserialize, Serialize}; - -#[derive(Serialize, Deserialize)] -pub struct OldOnEventJson { - pub on_save: Option, - pub on_load: Option, - pub on_set: Option, - pub on_resume: Option, -} - -#[derive(Serialize, Deserialize)] -pub struct OldSettingsJson { - pub version: u64, - pub name: String, - pub persistent: bool, - pub cpus: Vec, - pub gpu: super::GpuJson, - pub battery: super::BatteryJson, - pub provider: Option, - pub events: Option, - pub tags: Vec, -} - -impl From<&OldSettingsJson> for super::SettingsJson { - fn from(old_settings: &OldSettingsJson) -> Self { - Self { - version: old_settings.version, - name: old_settings.name.clone(), - variant: 0, - persistent: old_settings.persistent, - cpus: old_settings.cpus.clone(), - gpu: old_settings.gpu.clone(), - battery: old_settings.battery.clone(), - provider: old_settings.provider.clone(), - tags: todo!(), - } - } -} - -impl From<&OldSettingsJson> for super::FileJson { - fn from(old_settings: &OldSettingsJson) -> Self { - let mut variants = HashMap::new(); - let variant = super::SettingsJson::from(old_settings); - variants.insert(0, variant); - - Self { - version: super::LATEST_VERSION, - name: old_settings.name.clone(), - variants, - app_id: todo!(), - } - } -} +pub mod gpu; +pub mod settings; diff --git a/backend/src/persist/migration/gpu.rs b/backend/src/persist/migration/gpu.rs new file mode 100644 index 0000000..6f71a4e --- /dev/null +++ b/backend/src/persist/migration/gpu.rs @@ -0,0 +1,26 @@ +use serde::{Deserialize, Serialize}; + +use crate::persist::{GpuJson, MinMaxJson}; + +#[derive(Serialize, Deserialize, Clone)] +pub struct OldGpuJson { + pub fast_ppt: Option, + pub slow_ppt: Option, + pub clock_limits: Option>, + pub slow_memory: bool, + pub root: Option, +} + +impl From for GpuJson { + fn from(old_gpu: OldGpuJson) -> Self { + Self { + fast_ppt: old_gpu.fast_ppt, + slow_ppt: old_gpu.slow_ppt, + tdp: None, + tdp_boost: None, + clock_limits: old_gpu.clock_limits.clone(), + memory_clock: None, + root: old_gpu.root.clone(), + } + } +} diff --git a/backend/src/persist/migration/settings.rs b/backend/src/persist/migration/settings.rs new file mode 100644 index 0000000..3d95bf6 --- /dev/null +++ b/backend/src/persist/migration/settings.rs @@ -0,0 +1,58 @@ +use std::collections::HashMap; + +use serde::{Deserialize, Serialize}; + +use crate::persist::{BatteryJson, CpuJson, DriverJson, FileJson, SettingsJson, LATEST_VERSION}; + +use super::gpu::OldGpuJson; + +#[derive(Serialize, Deserialize, Clone)] +pub struct OldOnEventJson { + pub on_save: Option, + pub on_load: Option, + pub on_set: Option, + pub on_resume: Option, +} + +#[derive(Serialize, Deserialize, Clone)] +pub struct OldSettingsJson { + pub version: u64, + pub name: String, + pub persistent: bool, + pub cpus: Vec, + pub gpu: OldGpuJson, + pub battery: BatteryJson, + pub provider: Option, + pub events: Option, +} + +impl From for SettingsJson { + fn from(old_settings: OldSettingsJson) -> Self { + Self { + version: old_settings.version, + name: old_settings.name.clone(), + variant: 0, + persistent: old_settings.persistent, + cpus: old_settings.cpus.clone(), + gpu: old_settings.gpu.clone().into(), + battery: old_settings.battery.clone(), + provider: old_settings.provider.clone(), + tags: Vec::new(), + } + } +} + +impl From for FileJson { + fn from(old_settings: OldSettingsJson) -> Self { + let mut variants = HashMap::new(); + let variant = SettingsJson::from(old_settings.clone()); + variants.insert(0, variant); + + Self { + version: LATEST_VERSION, + name: old_settings.name.clone(), + app_id: todo!(), + variants, + } + } +} diff --git a/backend/src/persist/mod.rs b/backend/src/persist/mod.rs index 561e6c1..d856fa8 100644 --- a/backend/src/persist/mod.rs +++ b/backend/src/persist/mod.rs @@ -13,7 +13,7 @@ pub use driver::DriverJson; pub use file::FileJson; pub use general::{MinMaxJson, SettingsJson}; pub use gpu::GpuJson; -pub use migration::OldSettingsJson; +pub use migration::{gpu::*, settings::*}; pub use error::{RonError, SerdeError};