From ebf600d96e8ff44b5ce6468458f36e0b66850fdf Mon Sep 17 00:00:00 2001 From: Wang Guan Date: Fri, 14 Jul 2023 00:00:03 +0900 Subject: [PATCH] do not overwrite unchanged cached Credentials (#1168) --- core/src/authentication.rs | 2 +- core/src/session.rs | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/core/src/authentication.rs b/core/src/authentication.rs index a536b558..8122d659 100644 --- a/core/src/authentication.rs +++ b/core/src/authentication.rs @@ -27,7 +27,7 @@ impl From for Error { } /// The credentials are used to log into the Spotify API. -#[derive(Debug, Clone, Default, Serialize, Deserialize)] +#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)] pub struct Credentials { pub username: String, diff --git a/core/src/session.rs b/core/src/session.rs index 5f08b134..69125e17 100755 --- a/core/src/session.rs +++ b/core/src/session.rs @@ -176,7 +176,13 @@ impl Session { self.set_username(&reusable_credentials.username); if let Some(cache) = self.cache() { if store_credentials { - cache.save_credentials(&reusable_credentials); + let cred_changed = cache + .credentials() + .map(|c| c != reusable_credentials) + .unwrap_or(true); + if cred_changed { + cache.save_credentials(&reusable_credentials); + } } }