@@ -1422,7 +1422,7 @@ impl ProcessingState {
14221422 ) -> Result < RwLockReadGuardArc < ( ) > , AssetReaderError > {
14231423 let infos = self . asset_infos . read ( ) . await ;
14241424 let info = infos
1425- . get ( path)
1425+ . get_recursive ( path)
14261426 . ok_or_else ( || AssetReaderError :: NotFound ( path. path ( ) . to_owned ( ) ) ) ?;
14271427 Ok ( info. file_transaction_lock . read_arc ( ) . await )
14281428 }
@@ -1432,7 +1432,7 @@ impl ProcessingState {
14321432 self . wait_until_initialized ( ) . await ;
14331433 let mut receiver = {
14341434 let infos = self . asset_infos . write ( ) . await ;
1435- let info = infos. get ( & path) ;
1435+ let info = infos. get_recursive ( & path) ;
14361436 match info {
14371437 Some ( info) => match info. status {
14381438 Some ( result) => return result,
@@ -1608,6 +1608,33 @@ impl ProcessorAssetInfos {
16081608 self . infos . get ( asset_path)
16091609 }
16101610
1611+ /// Gets the [`ProcessorAssetInfo`] associated with `asset_path`, but also looks for directories
1612+ /// above that are considered processed assets.
1613+ pub ( crate ) fn get_recursive (
1614+ & self ,
1615+ asset_path : & AssetPath < ' static > ,
1616+ ) -> Option < & ProcessorAssetInfo > {
1617+ if let Some ( info) = self . infos . get ( asset_path) {
1618+ // Avoid cloning if the path we get has info.
1619+ return Some ( info) ;
1620+ }
1621+
1622+ // Either the path isn't present at all, or the path is actually a subdirectory of a "multi"
1623+ // processed asset. So keep exploring up until we're sure there isn't a directory being
1624+ // processed.
1625+ let mut path_current = asset_path. clone_owned ( ) ;
1626+
1627+ // PERF: This traverse up is expensive due to needing many allocations. We could use a more
1628+ // appropriate data structure like a trie instead.
1629+ while let Some ( path_parent) = path_current. parent ( ) {
1630+ path_current = path_parent;
1631+ if let Some ( info) = self . infos . get ( & path_current) {
1632+ return Some ( info) ;
1633+ }
1634+ }
1635+ None
1636+ }
1637+
16111638 fn get_mut ( & mut self , asset_path : & AssetPath < ' static > ) -> Option < & mut ProcessorAssetInfo > {
16121639 self . infos . get_mut ( asset_path)
16131640 }
0 commit comments