Skip to content

Commit

Permalink
temp [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
benfdking committed May 23, 2024
1 parent 727dc56 commit 67a2126
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 13 deletions.
5 changes: 5 additions & 0 deletions rust/core/src/automatic_branching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,11 @@ pub type ModelNameString = String;

pub type ShortenedHash<'a> = &'a str;

/// model_name_with_hash_to_model converts
pub fn model_name_with_hash_to_model_name<'a>(name: ModelWithHash<'a>) -> ModelName<'a> {
&name[4..name.len() - 8]
}

/// given_map_and_hash_map_return_sub_graph_all_cached takes a graph and a map of the model to the
/// shortened hashes and returns a set that includes the model names of the models that are cached.
///
Expand Down
48 changes: 35 additions & 13 deletions rust/core/src/automatic_branching_build_cached.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,59 @@
use crate::{
automatic_branching::{derive_hash_views, is_cache_full_path},
databases::DatabaseQueryGenerator,
automatic_branching::{
derive_hash_views, is_cache_full_path, model_name_with_hash_to_model_name,
},
databases::{CacheStatus, DatabaseQueryGenerator},
file_system::FileSystem,
graph::project_to_graph,
project::project_and_fs_to_sql_for_views,
};
use quary_proto::Project;
use std::collections::{BTreeMap, BTreeSet, HashSet};
use std::collections::{BTreeMap, HashSet};

fn build_only_non_cached_things(
async fn build_only_non_cached_things(
project: &Project,
file_system: &impl FileSystem,
database: &impl DatabaseQueryGenerator,
view_paths_in_target: HashSet<String>,
) -> Result<BTreeMap<String, Vec<String>>, String> {
let filtered_cache_views = view_paths_in_target
let filtered_cache_views_paths = view_paths_in_target
.into_iter()
.map(|name| {
let is_cache = is_cache_full_path(database, &name)?;
Ok((name, is_cache))
.map(|path| {
let is_cache = is_cache_full_path(database, &path)?;
Ok((path, is_cache))
})
.collect::<Result<BTreeMap<String, bool>, String>>()?
.into_iter()
.filter(|(_, is_cache)| !is_cache)
.collect::<BTreeSet<_>>();
.map(|(path, _)| {
let name = database.return_full_path_requirement(&path);
let name_without_hash = model_name_with_hash_to_model_name(&name);
(name_without_hash.to_string(), (name.to_string(), path.to_string()))
})
.collect::<BTreeMap<String, (String, String)>>();

let views_to_create =
project_and_fs_to_sql_for_views(project, file_system, database, false, false);
project_and_fs_to_sql_for_views(project, file_system, database, false, false).await?;

let graph = project_to_graph(project.clone())?;
let hashed_views = derive_hash_views(database, project, &graph)?;

let graph = project_to_graph(project.clone());
let hashed_views = derive_hash_views(database, project, graph);
let views_to_create = views_to_create.into_iter().map(|(name, view)| {
let new_name_with_hash = hashed_views.get(&name).ok_or(
format!("Could not find view with name: {}", name),
)?;


let existing_name_with_hash = filtered_cache_views_paths.get(&name);
if let Some(existing_name_with_hash) = existing_name_with_hash {
if existing_name_with_hash == new_name_with_hash {
Ok((name, (CacheStatus::CachedAndMatching, new_name_with_hash)))
} else {
Ok( (name, (CacheStatus::NotMatching, new_name_with_hash)))
}
} else {
Ok( (name, (CacheStatus::NotMatching, new_name_with_hash)))
}
});

unimplemented!();
}

0 comments on commit 67a2126

Please sign in to comment.