[Bf-blender-cvs] [a07a2e2369d] temp-asset-library-all: Avoid redundant loading of catalogs and "All" library processing
Julian Eisel
noreply at git.blender.org
Fri Dec 2 20:29:30 CET 2022
Commit: a07a2e2369d0290d08e124aa53d56cfd4600e341
Author: Julian Eisel
Date: Fri Dec 2 19:32:46 2022 +0100
Branches: temp-asset-library-all
https://developer.blender.org/rBa07a2e2369d0290d08e124aa53d56cfd4600e341
Avoid redundant loading of catalogs and "All" library processing
===================================================================
M source/blender/asset_system/AS_asset_library.hh
M source/blender/asset_system/intern/asset_library_service.cc
M source/blender/editors/space_file/filelist.cc
===================================================================
diff --git a/source/blender/asset_system/AS_asset_library.hh b/source/blender/asset_system/AS_asset_library.hh
index 3f2562aa987..6526e3e8382 100644
--- a/source/blender/asset_system/AS_asset_library.hh
+++ b/source/blender/asset_system/AS_asset_library.hh
@@ -84,8 +84,7 @@ class AssetLibrary {
* library. This is just a combination of the other ones, so usually
* iterating over it is redundant.
*/
- static void foreach_loaded(FunctionRef<void(AssetLibrary &)> fn,
- bool include_all_library = true);
+ static void foreach_loaded(FunctionRef<void(AssetLibrary &)> fn, bool include_all_library);
void load_catalogs();
diff --git a/source/blender/asset_system/intern/asset_library_service.cc b/source/blender/asset_system/intern/asset_library_service.cc
index 430de903db7..fbcda02025c 100644
--- a/source/blender/asset_system/intern/asset_library_service.cc
+++ b/source/blender/asset_system/intern/asset_library_service.cc
@@ -155,20 +155,25 @@ AssetLibrary *AssetLibraryService::get_asset_library_all(const Main *bmain)
all_library_ = std::make_unique<AssetLibrary>();
AssetLibrary &all_library = *all_library_;
- auto build_catalogs_fn = [&all_library]() {
+ auto build_catalogs_fn = [&all_library](const bool is_first_load) {
/* Start with empty catalog storage. */
all_library.catalog_service = std::make_unique<AssetCatalogService>();
/* (Re-)load catalogs on refresh. */
- AssetLibrary::foreach_loaded([&all_library](AssetLibrary &nested) {
- nested.catalog_service->reload_catalogs();
- all_library.catalog_service->add_from_existing(*nested.catalog_service);
- });
+ AssetLibrary::foreach_loaded(
+ [&](AssetLibrary &nested) {
+ /* On first load the catalogs were read just above, no need to reload. */
+ if (!is_first_load) {
+ nested.catalog_service->reload_catalogs();
+ }
+ all_library.catalog_service->add_from_existing(*nested.catalog_service);
+ },
+ false);
all_library.catalog_service->rebuild_tree();
};
- build_catalogs_fn();
- all_library.on_refresh_ = build_catalogs_fn;
+ build_catalogs_fn(true);
+ all_library.on_refresh_ = [build_catalogs_fn]() { build_catalogs_fn(false); };
return &all_library;
}
diff --git a/source/blender/editors/space_file/filelist.cc b/source/blender/editors/space_file/filelist.cc
index 60c34ceda5f..2bf91efc610 100644
--- a/source/blender/editors/space_file/filelist.cc
+++ b/source/blender/editors/space_file/filelist.cc
@@ -3907,18 +3907,20 @@ static void filelist_readjob_all_asset_library(FileListReadJob *job_params,
/* The "All" asset library was loaded, which means all other asset libraries are also loaded.
* Load their assets from disk into the "All" library. */
- asset_system::AssetLibrary::foreach_loaded([&](asset_system::AssetLibrary &nested_library) {
- StringRefNull root_path = nested_library.root_path();
- if (root_path.is_empty()) {
- return;
- }
+ asset_system::AssetLibrary::foreach_loaded(
+ [&](asset_system::AssetLibrary &nested_library) {
+ StringRefNull root_path = nested_library.root_path();
+ if (root_path.is_empty()) {
+ return;
+ }
- /* Override library info to read this library. */
- job_params->load_asset_library = &nested_library;
- BLI_strncpy(filelist->filelist.root, root_path.c_str(), sizeof(filelist->filelist.root));
+ /* Override library info to read this library. */
+ job_params->load_asset_library = &nested_library;
+ BLI_strncpy(filelist->filelist.root, root_path.c_str(), sizeof(filelist->filelist.root));
- filelist_readjob_recursive_dir_add_items(true, job_params, stop, do_update, progress);
- });
+ filelist_readjob_recursive_dir_add_items(true, job_params, stop, do_update, progress);
+ },
+ false);
}
/**
More information about the Bf-blender-cvs
mailing list