jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/697138 )
Change subject: [bugfix] remove lru_cache from botMayEdit method ......................................................................
[bugfix] remove lru_cache from botMayEdit method
- lru_cache keeps all page references and leads to exhausting memory usage if a lot of pages are loaded. See also https://bugs.python.org/issue19859 Replace lru_cache by the Page attribute "_bot_may_edit" - delete this cache attribute if a page is reloaded with Page.get(force) from life wiki because the content can have been changed
Bug: T283957 Change-Id: Ia491a9e70203634e722caaa8e50a7388057376aa --- M pywikibot/page/__init__.py 1 file changed, 9 insertions(+), 2 deletions(-)
Approvals: Zhuyifei1999: Looks good to me, but someone else must approve Rubin: Looks good to me, but someone else must approve Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/page/__init__.py b/pywikibot/page/__init__.py index dc4542d..c6048e8 100644 --- a/pywikibot/page/__init__.py +++ b/pywikibot/page/__init__.py @@ -30,7 +30,7 @@
import pywikibot from pywikibot import config, i18n, textlib -from pywikibot.backports import Dict, Iterable, List, Tuple, cache +from pywikibot.backports import Dict, Iterable, List, Tuple from pywikibot.comms import http from pywikibot.exceptions import ( APIError, @@ -440,6 +440,8 @@ """ if force: del self.latest_revision_id + if hasattr(self, '_bot_may_edit'): + del self._bot_may_edit try: self._getInternals() except IsRedirectPageError: @@ -1017,7 +1019,6 @@ """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. @@ -1033,6 +1034,12 @@ to override this by setting ignore_bot_templates=True in user-config.py, or using page.put(force=True). """ + if not hasattr(self, '_bot_may_edit'): + self._bot_may_edit = self._check_bot_may_edit() + return self._bot_may_edit + + def _check_bot_may_edit(self) -> bool: + """A botMayEdit helper method.""" if not hasattr(self, 'templatesWithParams'): return True
pywikibot-commits@lists.wikimedia.org