[Bf-blender-cvs] [e8990fd220c] functions: cache node group names in .blend file

Jacques Lucke noreply at git.blender.org
Thu Dec 19 13:21:59 CET 2019


Commit: e8990fd220cdb32f74792fdb3e7537caa02212c0
Author: Jacques Lucke
Date:   Thu Dec 19 13:21:06 2019 +0100
Branches: functions
https://developer.blender.org/rBe8990fd220cdb32f74792fdb3e7537caa02212c0

cache node group names in .blend file

===================================================================

M	release/scripts/startup/nodes/search.py

===================================================================

diff --git a/release/scripts/startup/nodes/search.py b/release/scripts/startup/nodes/search.py
index 14840533db5..4453b6ddae8 100644
--- a/release/scripts/startup/nodes/search.py
+++ b/release/scripts/startup/nodes/search.py
@@ -3,6 +3,12 @@ from bpy.props import *
 from pathlib import Path
 from . base import BaseNode
 from . utils.enum_items_cache import cache_enum_items
+from functools import lru_cache
+
+ at lru_cache()
+def get_node_group_names_in_file(path: str):
+    with bpy.data.libraries.load(path) as (data_from, data_to):
+        return list(data_from.node_groups)
 
 class NodeSearch(bpy.types.Operator):
     bl_idname = "fn.node_search"
@@ -28,11 +34,10 @@ class NodeSearch(bpy.types.Operator):
         for path in nodelibdir.glob("**/*.blend"):
             if not path.is_file():
                 continue
-            with bpy.data.libraries.load(str(path)) as (data_from, data_to):
-                for group_name in data_from.node_groups:
-                    if group_name not in local_group_names:
-                        item = encode_search_item(("LIB_GROUP", str(path), group_name), "(G) " + group_name)
-                        items.append(item)
+            for group_name in get_node_group_names_in_file(str(path)):
+                if group_name not in local_group_names:
+                    item = encode_search_item(("LIB_GROUP", str(path), group_name), "(G) " + group_name)
+                    items.append(item)
 
         sorted_items = list(sorted(items, key=lambda item: item[1]))
         return sorted_items



More information about the Bf-blender-cvs mailing list