Addons search also search addon description #27356

Closed
opened 2011-05-10 19:58:52 +02:00 by Davis Sorenson · 17 comments

%%%This patch makes the addons search also search the addon descriptions, allowing for more detailed searches. Very simple patch, only affects two lines.%%%

%%%This patch makes the addons search also search the addon descriptions, allowing for more detailed searches. Very simple patch, only affects two lines.%%%
Author

Changed status to: 'Open'

Changed status to: 'Open'

%%% Patch is fine.

But would like to hear your opinion Luca if this is useful. Assigning to you. %%%

%%% Patch is fine. But would like to hear your opinion Luca if this is useful. Assigning to you. %%%

%%%I prefer that more advanced search options cache results rather then updating them on draw.%%%

%%%I prefer that more advanced search options cache results rather then updating them on draw.%%%

%%%But it's not that much to search in this case, and it's not slow. Caching could be better used elsewhere.%%%

%%%But it's not that much to search in this case, and it's not slow. Caching could be better used elsewhere.%%%

Added subscriber: @mont29

Added subscriber: @mont29

Is this patch still relevant/alive?

Is this patch still relevant/alive?
Author

Patch still applies and works. If nobody has objections to the patch as it is, I would like to see it applied to master.

Patch still applies and works. If nobody has objections to the patch as it is, I would like to see it applied to master.
mindrones was unassigned by Bastien Montagne 2014-09-23 14:50:20 +02:00
Bastien Montagne self-assigned this 2014-09-23 14:50:20 +02:00

Ok, but would do it a bit differently then (and as suggested by campbell, making a search cache could help here too, maybe build a set with all words from title + author + description when scanning addons, e.g.).

Will see that after release.

Ok, but would do it a bit differently then (and as suggested by campbell, making a search cache could help here too, maybe build a set with all words from title + author + description when scanning addons, e.g.). Will see that after release.

Added subscriber: @michaelknubben

Added subscriber: @michaelknubben

If it doesn't impact the speed of searching, this seems like a definite improvement!

If it doesn't impact the speed of searching, this seems like a definite improvement!
Author

After investigating this, I don't think that performance is an issue.
I ran the attached performance test on all the addon author/name/description data, which runs the search a total of 20k times (10k with a findable search, 10k with a randomly generated string) and got the following result (I selected the worst-performing one):

$ python timer.py
('Searching 10k findable and 10k (probably) unfindable items takes:', 1.913896083831787, 'seconds')

timer.py

names.txt

descriptions.txt

authors.txt

After investigating this, I don't think that performance is an issue. I ran the attached performance test on all the addon author/name/description data, which runs the search a total of 20k times (10k with a findable search, 10k with a randomly generated string) and got the following result (I selected the worst-performing one): ``` $ python timer.py ('Searching 10k findable and 10k (probably) unfindable items takes:', 1.913896083831787, 'seconds') ``` [timer.py](https://archive.blender.org/developer/F111991/timer.py) [names.txt](https://archive.blender.org/developer/F111992/names.txt) [descriptions.txt](https://archive.blender.org/developer/F111993/descriptions.txt) [authors.txt](https://archive.blender.org/developer/F111994/authors.txt)

Here is a quick cached implementation:
P147: (An Untitled Masterwork)

diff --git a/release/scripts/startup/bl_ui/space_userpref.py b/release/scripts/startup/bl_ui/space_userpref.py
index 59b842a..f4b9cd6 100644
--- a/release/scripts/startup/bl_ui/space_userpref.py
+++ b/release/scripts/startup/bl_ui/space_userpref.py
@@ -1171,6 +1171,10 @@ class USERPREF_PT_addons(Panel):
         'TESTING': 'MOD_EXPLODE',
         }
 
+    # Class var is not ideal (becomes useless in case more than one addons panel is used),
+    # but should be good enough in most cases!
+    _search_cache = ["", set()]
+
     @classmethod
     def poll(cls, context):
         userpref = context.user_preferences
@@ -1201,6 +1205,26 @@ class USERPREF_PT_addons(Panel):
         for l in lines[1:]:
             box.label(l)
 
+    def filter_search_addons(self, search, addons):
+        old_search, results = self._search_cache
+        if not search:
+            for addon in addons:
+                yield addon
+        elif old_search != search:
+            results.clear()
+            self._search_cache- [x] = search
+            for addon in addons:
+                mod, info = addon
+                if (search in info["name"].lower() or
+                    (info["author"] and search in info["author"].lower()) or
+                    (info["description"] and search in info["description"].lower())):
+                        results.add(mod.__name__)
+                        yield addon
+        else:
+            for addon in addons:
+                if addon- [x].__name__ in results:
+                    yield addon
+
     def draw(self, context):
         import os
         import addon_utils
@@ -1249,7 +1273,7 @@ class USERPREF_PT_addons(Panel):
         # initialized on demand
         user_addon_paths = []
 
-        for mod, info in addons:
+        for mod, info in self.filter_search_addons(search, addons):
             module_name = mod.__name__
 
             is_enabled = module_name in used_ext
@@ -1265,13 +1289,6 @@ class USERPREF_PT_addons(Panel):
                 (filter == "User" and (mod.__file__.startswith((scripts_addons_folder, userpref_addons_folder))))
                 ):
 
-                if search and search not in info["name"].lower():
-                    if info["author"]:
-                        if search not in info["author"].lower():
-                            continue
-                    else:
-                        continue
-
                 # Addon UI Code
                 col_box = col.column()
                 box = col_box.box()

About speed: cached is about ten times quicker than uncached (~0.12sec instead of 1.2sec for 10K here, with all addons) - and without description search, uncached search is about five times slower (~0.7 secs)... So caching is worth it!

However, not sure clas var is OK here… Campbell, what do you say?

Here is a quick cached implementation: [P147: (An Untitled Masterwork)](https://archive.blender.org/developer/P147.txt) ``` diff --git a/release/scripts/startup/bl_ui/space_userpref.py b/release/scripts/startup/bl_ui/space_userpref.py index 59b842a..f4b9cd6 100644 --- a/release/scripts/startup/bl_ui/space_userpref.py +++ b/release/scripts/startup/bl_ui/space_userpref.py @@ -1171,6 +1171,10 @@ class USERPREF_PT_addons(Panel): 'TESTING': 'MOD_EXPLODE', } + # Class var is not ideal (becomes useless in case more than one addons panel is used), + # but should be good enough in most cases! + _search_cache = ["", set()] + @classmethod def poll(cls, context): userpref = context.user_preferences @@ -1201,6 +1205,26 @@ class USERPREF_PT_addons(Panel): for l in lines[1:]: box.label(l) + def filter_search_addons(self, search, addons): + old_search, results = self._search_cache + if not search: + for addon in addons: + yield addon + elif old_search != search: + results.clear() + self._search_cache- [x] = search + for addon in addons: + mod, info = addon + if (search in info["name"].lower() or + (info["author"] and search in info["author"].lower()) or + (info["description"] and search in info["description"].lower())): + results.add(mod.__name__) + yield addon + else: + for addon in addons: + if addon- [x].__name__ in results: + yield addon + def draw(self, context): import os import addon_utils @@ -1249,7 +1273,7 @@ class USERPREF_PT_addons(Panel): # initialized on demand user_addon_paths = [] - for mod, info in addons: + for mod, info in self.filter_search_addons(search, addons): module_name = mod.__name__ is_enabled = module_name in used_ext @@ -1265,13 +1289,6 @@ class USERPREF_PT_addons(Panel): (filter == "User" and (mod.__file__.startswith((scripts_addons_folder, userpref_addons_folder)))) ): - if search and search not in info["name"].lower(): - if info["author"]: - if search not in info["author"].lower(): - continue - else: - continue - # Addon UI Code col_box = col.column() box = col_box.box() ``` About speed: cached is about ten times quicker than uncached (~0.12sec instead of 1.2sec for 10K here, with all addons) - and without description search, uncached search is about five times slower (~0.7 secs)... So caching is worth it! However, not sure clas var is OK here… Campbell, what do you say?

It makes sense to cache, but would be nice if we could throw away the cache too (when the UI is no longer active).

For this only - its not big deal, but rather each panel doesnt store cache for the entire blender session.

It could be made so the classes __del__ method can handle that, though at the moment IIRC the panel is created for each draw.

It makes sense to cache, but would be nice if we could throw away the cache too (when the UI is no longer active). For this only - its not big deal, but rather each panel doesnt store cache for the entire blender session. It could be made so the classes `__del__` method can handle that, though at the moment IIRC the panel is created for each draw.

@Campbell yes, panels are recreated at each draw, that’s why I used the panel's class itself as storage… Not really good I know.

But anyway, I don't think we have any way to achieve a nice clearing of the cache currently, adding it to Space (if it was possible - afaik it is not currently) would not really solve it, since I think spaces are never freed once created (unless you close the related 'window', would work for userprefs, but…)?

@Campbell yes, panels are recreated at each draw, that’s why I used the panel's class itself as storage… Not really good I know. But anyway, I don't think we have any way to achieve a nice clearing of the cache currently, adding it to Space (if it was possible - afaik it is not currently) would not really solve it, since I think spaces are never freed once created (unless you close the related 'window', would work for userprefs, but…)?

I think its reasonable to have some way to free the cache at some point (when the window closes or the addons are navigated away from). but this means we have to add some way for the UI to handle cache.

We could look into a way to have some time-out which clears the cache, though currently Blender/Python thread stuff is risky business.

I think its reasonable to have some way to free the cache at some point (when the window closes or the addons are navigated away from). but this means we have to add some way for the UI to handle cache. We could look into a way to have some time-out which clears the cache, though currently Blender/Python thread stuff is risky business.

Changed status from 'Open' to: 'Archived'

Changed status from 'Open' to: 'Archived'

No response on this in a long time, closing.

No response on this in a long time, closing.
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
6 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#27356
No description provided.