mirror of
				https://github.com/lov3b/ecb-rates.git
				synced 2025-11-03 23:00:21 +01:00 
			
		
		
		
	Only overwrite old cache if an update was made
This commit is contained in:
		
							
								
								
									
										9
									
								
								src/cache/cache_line.rs
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										9
									
								
								src/cache/cache_line.rs
									
									
									
									
										vendored
									
									
								
							@@ -9,7 +9,7 @@ use crate::Hollidays;
 | 
			
		||||
 | 
			
		||||
const CET: FixedOffset = unsafe { FixedOffset::east_opt(3600).unwrap_unchecked() };
 | 
			
		||||
 | 
			
		||||
#[derive(Serialize, Deserialize, Debug)]
 | 
			
		||||
#[derive(Serialize, Deserialize, Debug, PartialEq)]
 | 
			
		||||
pub struct CacheLine {
 | 
			
		||||
    #[serde(with = "ts_seconds")]
 | 
			
		||||
    date: DateTime<Utc>,
 | 
			
		||||
@@ -86,6 +86,13 @@ impl CacheLine {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl PartialEq<Vec<ExchangeRateResult>> for CacheLine {
 | 
			
		||||
    fn eq(&self, other: &Vec<ExchangeRateResult>) -> bool {
 | 
			
		||||
        &self.exchange_rate_results == other
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[cfg(test)]
 | 
			
		||||
mod tests {
 | 
			
		||||
    use super::*;
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										12
									
								
								src/main.rs
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								src/main.rs
									
									
									
									
									
								
							@@ -65,7 +65,18 @@ async fn main() -> ExitCode {
 | 
			
		||||
                return ExitCode::FAILURE;
 | 
			
		||||
            }
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        if !cache_ok {
 | 
			
		||||
            let not_equal_cache = cache.as_ref().map_or_else(
 | 
			
		||||
                || true,
 | 
			
		||||
                |cache_local| {
 | 
			
		||||
                    cache_local
 | 
			
		||||
                        .get_cache_line(cli.resolution)
 | 
			
		||||
                        .map_or_else(|| true, |cache_line| cache_line == &parsed)
 | 
			
		||||
                },
 | 
			
		||||
            );
 | 
			
		||||
 | 
			
		||||
            if not_equal_cache {
 | 
			
		||||
                if let Some(cache_safe) = cache.as_mut() {
 | 
			
		||||
                    let cache_line = CacheLine::new(parsed.clone());
 | 
			
		||||
                    cache_safe.set_cache_line(cli.resolution, cache_line);
 | 
			
		||||
@@ -74,6 +85,7 @@ async fn main() -> ExitCode {
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        parsed
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
use serde::{Deserialize, Serialize};
 | 
			
		||||
use std::collections::HashMap;
 | 
			
		||||
 | 
			
		||||
#[derive(Debug, Serialize, Deserialize, Clone)]
 | 
			
		||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
 | 
			
		||||
pub struct ExchangeRateResult {
 | 
			
		||||
    pub time: String,
 | 
			
		||||
    pub rates: HashMap<String, f64>,
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user