jenkins-bot submitted this change.

View Change

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
[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(-)

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


To view, visit change 697138. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ia491a9e70203634e722caaa8e50a7388057376aa
Gerrit-Change-Number: 697138
Gerrit-PatchSet: 4
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Dvorapa <dvorapa@seznam.cz>
Gerrit-Reviewer: Rubin <rubin.happy@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: Zhuyifei1999 <zhuyifei1999@gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged