Skip to content

Commit

Permalink
Merge pull request #4819 from systeminit/fix/dont-lookup-sv-repeatedely
Browse files Browse the repository at this point in the history
fix: don't lookup variant over and over in list funcs
  • Loading branch information
zacharyhamm authored Oct 17, 2024
2 parents 11e0b15 + a96d6b0 commit 6479fee
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions lib/sdf-server/src/service/v2/func/list_funcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use axum::{
use dal::func::binding::FuncBinding;
use dal::{ChangeSetId, DalContext, Func, SchemaId, SchemaVariant, SchemaVariantId, WorkspacePk};
use si_frontend_types as frontend_types;
use std::collections::{HashMap, HashSet};
use std::collections::HashMap;
use telemetry::prelude::*;

use super::FuncAPIResult;
Expand Down Expand Up @@ -49,11 +49,11 @@ async fn treat_single_function(

// check if it is to be filtered away
let mut schema_default_map: HashMap<SchemaId, SchemaVariantId> = HashMap::new();
let mut unlocked_variants = HashSet::new();
let mut unlocked_map: HashMap<SchemaVariantId, bool> = HashMap::new();

// If func is unlocked or intrinsic, we always use it,
// otherwise we return funcs that are bound to default variants
// OR not bound anything, OR editing variants
// OR not bound to anything, OR editing variants
if func.is_locked && !func.is_intrinsic() && !bindings.is_empty() {
let mut should_hide = true;
for binding in &bindings {
Expand All @@ -69,16 +69,6 @@ async fn treat_single_function(
should_hide = false;
}
} else {
if unlocked_variants.contains(&schema_variant_id) {
should_hide = false;
} else {
let variant = SchemaVariant::get_by_id_or_error(ctx, schema_variant_id).await?;
if !variant.is_locked() {
unlocked_variants.insert(schema_variant_id);
should_hide = false;
}
}

let default_for_schema =
SchemaVariant::get_default_id_for_schema(ctx, schema).await?;

Expand All @@ -88,6 +78,18 @@ async fn treat_single_function(
should_hide = false;
}
}

if let Some(is_unlocked) = unlocked_map.get(&schema_variant_id) {
if *is_unlocked {
should_hide = false;
}
} else {
let variant = SchemaVariant::get_by_id_or_error(ctx, schema_variant_id).await?;
if !variant.is_locked() {
should_hide = false;
}
unlocked_map.insert(schema_variant_id, !variant.is_locked());
}
}
if should_hide {
return Ok(None);
Expand Down

0 comments on commit 6479fee

Please sign in to comment.