refactor: avoid some clones while caching ns schema (#5896)

Found while reviewing the code.

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
pull/24376/head
Marco Neumann 2022-10-19 06:28:15 +00:00 committed by GitHub
parent d706f8221d
commit e1b50227f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 16 deletions

View File

@ -94,7 +94,7 @@ impl NamespaceCache {
.await
.expect("retry forever")?;
Some(Arc::new((&schema).into()))
Some(Arc::new(schema.into()))
}
});
let loader = Arc::new(MetricsLoader::new(
@ -214,8 +214,8 @@ impl CachedTable {
}
}
impl From<&TableSchema> for CachedTable {
fn from(table: &TableSchema) -> Self {
impl From<TableSchema> for CachedTable {
fn from(table: TableSchema) -> Self {
let mut column_id_map: HashMap<ColumnId, Arc<str>> = table
.columns
.iter()
@ -225,12 +225,7 @@ impl From<&TableSchema> for CachedTable {
Self {
id: table.id,
schema: Arc::new(
table
.clone()
.try_into()
.expect("Catalog table schema broken"),
),
schema: Arc::new(table.try_into().expect("Catalog table schema broken")),
column_id_map,
}
}
@ -254,14 +249,14 @@ impl CachedNamespace {
}
}
impl From<&NamespaceSchema> for CachedNamespace {
fn from(ns: &NamespaceSchema) -> Self {
impl From<NamespaceSchema> for CachedNamespace {
fn from(ns: NamespaceSchema) -> Self {
let mut tables: HashMap<Arc<str>, Arc<CachedTable>> = ns
.tables
.iter()
.into_iter()
.map(|(name, table)| {
let table: CachedTable = table.into();
(Arc::from(name.clone()), Arc::new(table))
(Arc::from(name), Arc::new(table))
})
.collect();
tables.shrink_to_fit();

View File

@ -474,7 +474,7 @@ pub mod tests {
}
async fn chunk(&self, namespace_schema: Arc<NamespaceSchema>) -> QuerierChunk {
let cached_namespace: CachedNamespace = namespace_schema.as_ref().into();
let cached_namespace: CachedNamespace = namespace_schema.as_ref().clone().into();
let cached_table = cached_namespace.tables.get("table").expect("table exists");
self.adapter
.new_chunk(

View File

@ -23,7 +23,7 @@ pub async fn querier_namespace_with_limit(
let schema = get_schema_by_name(&ns.namespace.name, repos.as_mut())
.await
.unwrap();
let cached_ns = Arc::new(CachedNamespace::from(&schema));
let cached_ns = Arc::new(CachedNamespace::from(schema));
let catalog_cache = Arc::new(QuerierCatalogCache::new_testing(
ns.catalog.catalog(),

View File

@ -930,7 +930,7 @@ impl MockIngester {
catalog_cache,
catalog.metric_registry(),
ns.namespace.name.clone().into(),
Arc::new(schema.as_ref().into()),
Arc::new(schema.as_ref().clone().into()),
catalog.exec(),
Some(ingester_connection),
sharder,