diff options
Diffstat (limited to 'cli/cache/incremental.rs')
-rw-r--r-- | cli/cache/incremental.rs | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/cli/cache/incremental.rs b/cli/cache/incremental.rs index 88520a031..d5298071f 100644 --- a/cli/cache/incremental.rs +++ b/cli/cache/incremental.rs @@ -172,7 +172,7 @@ impl SqlIncrementalCache { fn from_connection( conn: Connection, state_hash: u64, - cli_version: String, + cli_version: &'static str, ) -> Result<Self, AnyError> { initialize(&conn, cli_version)?; @@ -237,7 +237,10 @@ impl SqlIncrementalCache { } } -fn initialize(conn: &Connection, cli_version: String) -> Result<(), AnyError> { +fn initialize( + conn: &Connection, + cli_version: &'static str, +) -> Result<(), AnyError> { // INT doesn't store up to u64, so use TEXT for source_hash let query = format!( "{INITIAL_PRAGMAS} @@ -261,11 +264,11 @@ fn initialize(conn: &Connection, cli_version: String) -> Result<(), AnyError> { |row| row.get(0), ) .ok(); - if data_cli_version.as_deref() != Some(&cli_version) { + if data_cli_version.as_deref() != Some(cli_version) { conn.execute("DELETE FROM incrementalcache", params![])?; let mut stmt = conn .prepare("INSERT OR REPLACE INTO info (key, value) VALUES (?1, ?2)")?; - stmt.execute(params!["CLI_VERSION", &cli_version])?; + stmt.execute(params!["CLI_VERSION", cli_version])?; } Ok(()) @@ -280,9 +283,7 @@ mod test { #[test] pub fn sql_cache_general_use() { let conn = Connection::open_in_memory().unwrap(); - let cache = - SqlIncrementalCache::from_connection(conn, 1, "1.0.0".to_string()) - .unwrap(); + let cache = SqlIncrementalCache::from_connection(conn, 1, "1.0.0").unwrap(); let path = PathBuf::from("/mod.ts"); assert_eq!(cache.get_source_hash(&path), None); @@ -292,8 +293,7 @@ mod test { // try changing the cli version (should clear) let conn = cache.conn; let mut cache = - SqlIncrementalCache::from_connection(conn, 1, "2.0.0".to_string()) - .unwrap(); + SqlIncrementalCache::from_connection(conn, 1, "2.0.0").unwrap(); assert_eq!(cache.get_source_hash(&path), None); // add back the file to the cache @@ -310,9 +310,7 @@ mod test { // recreating the cache should not remove the data because the CLI version and state hash is the same let conn = cache.conn; - let cache = - SqlIncrementalCache::from_connection(conn, 1, "2.0.0".to_string()) - .unwrap(); + let cache = SqlIncrementalCache::from_connection(conn, 1, "2.0.0").unwrap(); assert_eq!(cache.get_source_hash(&path), Some(2)); // now try replacing and using another path @@ -328,8 +326,7 @@ mod test { pub async fn incremental_cache_general_use() { let conn = Connection::open_in_memory().unwrap(); let sql_cache = - SqlIncrementalCache::from_connection(conn, 1, "1.0.0".to_string()) - .unwrap(); + SqlIncrementalCache::from_connection(conn, 1, "1.0.0").unwrap(); let file_path = PathBuf::from("/mod.ts"); let file_text = "test"; let file_hash = FastInsecureHasher::new().write_str(file_text).finish(); |