MCPcopy Create free account
hub / github.com/hashintel/hash / get_samples

Function get_samples

tests/graph/benches/representative_read/seed.rs:293–362  ·  view source on GitHub ↗
(account_id: ActorEntityUuid, store_wrapper: &StoreWrapper)

Source from the content-addressed store, hash-verified

291}
292
293async fn get_samples(account_id: ActorEntityUuid, store_wrapper: &StoreWrapper) -> Samples {
294 let mut entity_types = HashMap::new();
295 entity_types.insert(
296 account_id,
297 SEED_ENTITY_TYPES
298 .into_iter()
299 .map(|entity_type_str| {
300 let entity_type: EntityType =
301 serde_json::from_str(entity_type_str).expect("could not parse entity type");
302 entity_type.id
303 })
304 .collect(),
305 );
306
307 let mut samples = Samples {
308 entities: HashMap::from([(account_id, HashMap::new())]),
309 entity_types,
310 };
311
312 let sample_map = samples
313 .entities
314 .get_mut(&account_id)
315 .expect("could not get sample map");
316
317 for entity_type_id in SEED_ENTITIES.map(|(entity_type_str, ..)| {
318 let entity_type: EntityType =
319 serde_json::from_str(entity_type_str).expect("could not parse entity type");
320 entity_type.id
321 }) {
322 // For now we'll just pick a sample of 50 entities.
323 let sample_entity_uuids = store_wrapper
324 .store
325 .as_client()
326 .query(
327 "
328 -- Very naive and slow sampling, we can replace when this becomes a bottleneck
329 SELECT entity_uuid FROM entity_temporal_metadata
330 INNER JOIN entity_is_of_type ON entity_is_of_type.entity_edition_id = \
331 entity_temporal_metadata.entity_edition_id
332 INNER JOIN ontology_ids ON ontology_ids.ontology_id = \
333 entity_is_of_type.entity_type_ontology_id
334 WHERE ontology_ids.base_url = $1 AND ontology_ids.version = $2
335 ORDER BY RANDOM()
336 LIMIT 50
337 ",
338 &[&entity_type_id.base_url, &entity_type_id.version],
339 )
340 .instrument(tracing::info_span!(
341 "SELECT",
342 otel.kind = "client",
343 db.system = "postgresql",
344 peer.service = "Postgres",
345 ))
346 .await
347 .unwrap_or_else(|err| {
348 panic!("failed to sample entities for entity type `{entity_type_id}`: {err}");
349 })
350 .into_iter()

Callers 1

Calls 11

collectMethod · 0.80
queryMethod · 0.80
as_clientMethod · 0.80
entryMethod · 0.80
fromFunction · 0.50
insertMethod · 0.45
mapMethod · 0.45
into_iterMethod · 0.45
expectMethod · 0.45
get_mutMethod · 0.45
extendMethod · 0.45

Tested by

no test coverage detected