This commit is contained in:
Florian THIERRY
2026-07-19 21:43:29 +02:00
parent 59b7164007
commit c3806f49ba
+31 -3
View File
@@ -153,9 +153,37 @@ impl LibraryItemSqliteRepository {
let raw_data = rows.map(Self::map_to_raw_entity).collect::<Vec<LibraryItemRawEntity>>()?;
Ok(None)
// Build a map of id to LibraryItemEntity for quick lookup
let mut entity_map: std::collections::HashMap<Uuid, LibraryItemEntity> = std::collections::HashMap::new();
// First pass: create all entities without parent relationships
for raw_entity in &raw_data {
let entity = LibraryItemEntity {
id: raw_entity.id.clone(),
name: raw_entity.name.clone(),
r#type: raw_entity.r#type,
parent_folder_id: None, // Will be set in second pass
};
entity_map.insert(raw_entity.id.clone(), entity);
}
// Second pass: set up parent-child relationships
for raw_entity in &raw_data {
if let Some(parent_id) = &raw_entity.parent_item_id {
if let Some(child_entity) = entity_map.get_mut(&raw_entity.id) {
if let Some(parent_entity) = entity_map.get(parent_id) {
child_entity.parent_folder_id = Some(Box::new(parent_entity.clone()));
}
}
}
}
// Find the requested item and return it with its full hierarchy
if let Some(entity) = entity_map.get(library_item_id) {
Ok(Some(entity.clone()))
} else {
Ok(None)
}
}
fn map_to_raw_entity(row: &Row) -> Result<LibraryItemRawEntity, Error> {