Addons search also search addon description
Closed, ArchivedPublic

Description

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

Details

Type
Patch

Related Objects

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.

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

Is this patch still relevant/alive?

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

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.

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

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')

Here is a quick cached implementation:

1diff --git a/release/scripts/startup/bl_ui/space_userpref.py b/release/scripts/startup/bl_ui/space_userpref.py
2index 59b842a..f4b9cd6 100644
3--- a/release/scripts/startup/bl_ui/space_userpref.py
4+++ b/release/scripts/startup/bl_ui/space_userpref.py
5@@ -1171,6 +1171,10 @@ class USERPREF_PT_addons(Panel):
6​ 'TESTING': 'MOD_EXPLODE',
7​ }
8
9+ # Class var is not ideal (becomes useless in case more than one addons panel is used),
10+ # but should be good enough in most cases!
11+ _search_cache = ["", set()]
12+
13​ @classmethod
14​ def poll(cls, context):
15​ userpref = context.user_preferences
16@@ -1201,6 +1205,26 @@ class USERPREF_PT_addons(Panel):
17​ for l in lines[1:]:
18​ box.label(l)
19
20+ def filter_search_addons(self, search, addons):
21+ old_search, results = self._search_cache
22+ if not search:
23+ for addon in addons:
24+ yield addon
25+ elif old_search != search:
26+ results.clear()
27+ self._search_cache[0] = search
28+ for addon in addons:
29+ mod, info = addon
30+ if (search in info["name"].lower() or
31+ (info["author"] and search in info["author"].lower()) or
32+ (info["description"] and search in info["description"].lower())):
33+ results.add(mod.__name__)
34+ yield addon
35+ else:
36+ for addon in addons:
37+ if addon[0].__name__ in results:
38+ yield addon
39+
40​ def draw(self, context):
41​ import os
42​ import addon_utils
43@@ -1249,7 +1273,7 @@ class USERPREF_PT_addons(Panel):
44​ # initialized on demand
45​ user_addon_paths = []
46
47- for mod, info in addons:
48+ for mod, info in self.filter_search_addons(search, addons):
49​ module_name = mod.__name__
50
51​ is_enabled = module_name in used_ext
52@@ -1265,13 +1289,6 @@ class USERPREF_PT_addons(Panel):
53​ (filter == "User" and (mod.__file__.startswith((scripts_addons_folder, userpref_addons_folder))))
54​ ):
55
56- if search and search not in info["name"].lower():
57- if info["author"]:
58- if search not in info["author"].lower():
59- continue
60- else:
61- continue
62-
63​ # Addon UI Code
64​ col_box = col.column()
65​ 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.

@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.

No response on this in a long time, closing.