Skip to content

Commit

Permalink
ConfigModel::apply don't fetch existing source (#25780)
Browse files Browse the repository at this point in the history
we can avoid fetching existing module source when applying a new config, since all we need are the paths.

GitOrigin-RevId: 524ff3b1950b8ced14dd73f8e68e8e63609291d3
  • Loading branch information
ldanilek authored and Convex, Inc. committed May 15, 2024
1 parent 0595553 commit 553ba73
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
16 changes: 11 additions & 5 deletions crates/model/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,21 @@ impl<'a, RT: Runtime> ConfigModel<'a, RT> {
let mut added_modules = BTreeSet::new();

// Add new modules.
let mut remaining_modules = ModuleModel::new(self.tx)
.get_application_modules(ComponentId::Root)
.await?;
let mut remaining_modules: BTreeSet<_> = ModuleModel::new(self.tx)
.get_application_metadata(ComponentId::Root)
.await?
.into_iter()
.map(|module| CanonicalizedComponentModulePath {
component: ComponentId::Root,
module_path: module.into_value().path,
})
.collect();
for module in modules {
let path = CanonicalizedComponentModulePath {
component: ComponentId::Root,
module_path: module.path.canonicalize(),
};
if remaining_modules.remove(&path).is_none() {
if !remaining_modules.remove(&path) {
added_modules.insert(path.clone());
}
let analyze_result = if !path.module_path.is_deps() {
Expand All @@ -230,7 +236,7 @@ impl<'a, RT: Runtime> ConfigModel<'a, RT> {
}

let mut removed_modules = BTreeSet::new();
for (path, _) in remaining_modules {
for path in remaining_modules {
removed_modules.insert(path.clone());
ModuleModel::new(self.tx).delete(path).await?;
}
Expand Down
13 changes: 13 additions & 0 deletions crates/model/src/modules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,19 @@ impl<'a, RT: Runtime> ModuleModel<'a, RT> {
Ok(modules)
}

pub async fn get_application_metadata(
&mut self,
component: ComponentId,
) -> anyhow::Result<Vec<ParsedDocument<ModuleMetadata>>> {
let modules = self
.get_all_metadata(component)
.await?
.into_iter()
.filter(|metadata| !metadata.path.is_system())
.collect();
Ok(modules)
}

/// Returns all registered modules that aren't system modules.
pub async fn get_application_modules(
&mut self,
Expand Down

0 comments on commit 553ba73

Please sign in to comment.