diff --git a/release/scripts/startup/bl_operators/wm.py b/release/scripts/startup/bl_operators/wm.py index 6d47fef371c..5a923b6861d 100644 --- a/release/scripts/startup/bl_operators/wm.py +++ b/release/scripts/startup/bl_operators/wm.py @@ -1241,19 +1241,46 @@ class WM_OT_doc_view_manual(Operator): doc_id: doc_id + @staticmethod + def _find_references_fnmatch(pattern, url_suffix, rna_id): + from re import match + from fnmatch import translate + return match(translate(pattern), rna_id), url_suffix + @staticmethod def _find_reference(rna_id, url_mapping, *, verbose=True): if verbose: print("online manual check for: '%s'... " % rna_id) - from fnmatch import fnmatchcase + + import multiprocessing + from re import match + from fnmatch import fnmatchcase, translate # XXX, for some reason all RNA ID's are stored lowercase # Adding case into all ID's isn't worth the hassle so force lowercase. rna_id = rna_id.lower() - for pattern, url_suffix in url_mapping: - if fnmatchcase(rna_id, pattern): - if verbose: - print(" match found: '%s' --> '%s'" % (pattern, url_suffix)) - return url_suffix + + cpu_count = multiprocessing.cpu_count() + if cpu_count == 1 or len(url_mapping) < 64: + for pattern, url_suffix in url_mapping: + if fnmatchcase(rna_id, pattern): + if verbose: + print(" match found: '%s' --> '%s'" % (pattern, url_suffix)) + return url_suffix + else: + def fnmatch_multiprocessing(url_mapping, rna_id): + # NOTE(@ideasman42): There are diminishing returns using more processes, + # in my testing above 8 is not significantly faster (sometimes slower). + with multiprocessing.Pool(processes=min(cpu_count, 8)) as pool: + return pool.starmap( + WM_OT_doc_view_manual._find_references_fnmatch, + [(*item, rna_id) for item in url_mapping] + ) + + for pattern, url_suffix in fnmatch_multiprocessing(url_mapping, rna_id): + if pattern is not None: + if verbose: + print(" match found: '%s' --> '%s'" % (pattern, url_suffix)) + return url_suffix if verbose: print("match not found") return None