Skip to content

Commit

Permalink
Merge pull request #66 from chaindexing/optimize-filter-maps
Browse files Browse the repository at this point in the history
Optimize filter maps
  • Loading branch information
Jurshsmith authored Mar 8, 2024
2 parents 64cecb2 + 22844da commit d470e39
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions chaindexing/src/contract_states/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,14 @@ pub trait ContractStateMigrations: Send + Sync {
fn get_reset_migrations(&self) -> Vec<String> {
self.get_migrations()
.iter()
.filter(|m| m.starts_with("CREATE TABLE IF NOT EXISTS"))
.map(|create_migration| {
let table_name = extract_table_name(create_migration);
.filter_map(|migration| {
if migration.starts_with("CREATE TABLE IF NOT EXISTS") {
let table_name = extract_table_name(migration);

format!("DROP TABLE IF EXISTS {table_name}")
Some(format!("DROP TABLE IF EXISTS {table_name}"))
} else {
None
}
})
.collect()
}
Expand All @@ -102,14 +105,19 @@ fn extract_table_fields(migration: &str, remove_json_fields: bool) -> Vec<String
.last()
.unwrap()
.split(',')
.filter(|field| remove_json_fields && !(field.contains("JSON") || field.contains("JSONB")))
.map(|field| {
field
.split_ascii_whitespace()
.collect::<Vec<&str>>()
.first()
.unwrap()
.to_string()
.filter_map(|field| {
if remove_json_fields && !(field.contains("JSON") || field.contains("JSONB")) {
Some(
field
.split_ascii_whitespace()
.collect::<Vec<&str>>()
.first()
.unwrap()
.to_string(),
)
} else {
None
}
})
.collect()
}
Expand Down

0 comments on commit d470e39

Please sign in to comment.