jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1336019?usp=email )

Change subject: category_graph: Cache subcategory lists
......................................................................

category_graph: Cache subcategory lists

Cache each category's sorted subcategories by site and title for the duration
of graph generation.

This avoids repeated API traversals when a category is reachable through
multiple parents while preserving per-path recursion and DOT edges.

Change-Id: I2428b54527d58d5cdd86d9fe95bc54df9dfed507
---
M scripts/category_graph.py
1 file changed, 10 insertions(+), 1 deletion(-)

Approvals:
  Xqt: Looks good to me, approved
  jenkins-bot: Verified




diff --git a/scripts/category_graph.py b/scripts/category_graph.py
index 6fd43f7..19836cb 100755
--- a/scripts/category_graph.py
+++ b/scripts/category_graph.py
@@ -108,6 +108,10 @@
         self.rev = defaultdict(list)
         self.fw = defaultdict(list)
         self.leaves = set()
+        self._subcat_cache: dict[
+            tuple[pywikibot.site.BaseSite, str],
+            list[pywikibot.Category],
+        ] = {}
         self.counter = 0
         font = 'fontname="Helvetica,Arial,sans-serif"'
         style = f'graph [rankdir=LR ranksep=2 concentrate=true {font}] ' \
@@ -126,7 +130,12 @@
         """
         title = cat.title(with_ns=False)
         size = float(self.args.downsize) ** level
-        subcats = sorted(cat.subcategories())
+        cache_key = cat.site, title
+        try:
+            subcats = self._subcat_cache[cache_key]
+        except KeyError:
+            subcats = sorted(cat.subcategories())
+            self._subcat_cache[cache_key] = subcats

         def node():
             subs = ', '.join([c.title(with_ns=False).replace(' ', ' ')

--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1336019?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I2428b54527d58d5cdd86d9fe95bc54df9dfed507
Gerrit-Change-Number: 1336019
Gerrit-PatchSet: 2
Gerrit-Owner: Mahveotm <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to