jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/645931 )
Change subject: [bugfix] cache botMayEdit result ......................................................................
[bugfix] cache botMayEdit result
Patch detached from bcc30f5
Bug: T267770 Change-Id: I34d258ea7018044c0fda067b0e5794a0f5ec449d --- M pywikibot/page/__init__.py 1 file changed, 5 insertions(+), 4 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/page/__init__.py b/pywikibot/page/__init__.py index 94e9c55..308dfe1 100644 --- a/pywikibot/page/__init__.py +++ b/pywikibot/page/__init__.py @@ -62,10 +62,13 @@ from pywikibot.tools import is_IP
if PYTHON_VERSION >= (3, 9): + from functools import cache Dict = dict List = list else: + from functools import lru_cache from typing import Dict, List + cache = lru_cache(None)
PROTOCOL_REGEX = r'\Ahttps?://' @@ -627,7 +630,7 @@ return ''
# check botMayEdit on a very early state (T262136) - self._bot_may_edit = self.botMayEdit() + self.botMayEdit() return self.latest_revision.text
@text.setter @@ -1093,6 +1096,7 @@ """DEPRECATED. Determine whether the page may be edited.""" return self.has_permission()
+ @cache def botMayEdit(self) -> bool: """ Determine whether the active bot is allowed to edit the page. @@ -1108,9 +1112,6 @@ to override this by setting ignore_bot_templates=True in user-config.py, or using page.put(force=True). """ - if hasattr(self, '_bot_may_edit'): - return self._bot_may_edit - if not hasattr(self, 'templatesWithParams'): return True
pywikibot-commits@lists.wikimedia.org