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

Change subject: titletranslate: Cache valid site codes
......................................................................

titletranslate: Cache valid site codes

Reuse one site-code set across hint and date translation instead of
rebuilding it for every candidate. Keep the lookup lazy for no-op calls.

Change-Id: Iafa5cfb99792a5cb14095a106ccffaa2a3b14cac
---
M pywikibot/titletranslate.py
1 file changed, 7 insertions(+), 2 deletions(-)

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




diff --git a/pywikibot/titletranslate.py b/pywikibot/titletranslate.py
index 2ae609b..be4648a 100644
--- a/pywikibot/titletranslate.py
+++ b/pywikibot/titletranslate.py
@@ -39,6 +39,7 @@
             'Either page or site parameter must be given with translate()')

     site = site or page.site
+    site_codes: set[str] | None = None
     result = set()

     if hints is None:
@@ -62,8 +63,10 @@
         else:
             codes = site.family.language_groups.get(code, code.split(','))

+        if site_codes is None:
+            site_codes = site.codes
         for newcode in codes:
-            if newcode in site.codes:
+            if newcode in site_codes:
                 if newcode != site.code:
                     ns = page.namespace() if page else 0
                     link = pywikibot.Link(newname,
@@ -81,8 +84,10 @@
         if dict_name:
             pywikibot.info(f'TitleTranslate: {page.title()} was recognized as '
                            f'{dict_name} with value {value}')
+            if site_codes is None:
+                site_codes = site.codes
             for entry_lang, entry in date.formats[dict_name].items():
-                if entry_lang not in site.codes:
+                if entry_lang not in site_codes:
                     continue

                 if entry_lang != page.site.lang:

--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1330574?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: Iafa5cfb99792a5cb14095a106ccffaa2a3b14cac
Gerrit-Change-Number: 1330574
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