do not overwrite unchanged cached Credentials (#1168)

This commit is contained in:
Wang Guan 2023-07-14 00:00:03 +09:00
parent c491f90e09
commit ebf600d96e
2 changed files with 8 additions and 2 deletions

View file

@ -27,7 +27,7 @@ impl From<AuthenticationError> 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,

View file

@ -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);
}
}
}