jenkins-bot has submitted this change and it was merged.
Change subject: [FIX] Page: Return cached text if possible ......................................................................
[FIX] Page: Return cached text if possible
This returns the cached text from Page.get() instead of requesting it each time again (of course unless forced). Also Page.get() does request the text for the first time twice which is reduced to one request.
This change makes Page.latest_revision also returned a cached revision which was changed into a non-cached version in 1de1e560.
Bug: T97960 Change-Id: I762009859f505dda85f680bbfae2ea38a2e04e2d --- M pywikibot/page.py 1 file changed, 12 insertions(+), 3 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py index 5195f59..26fdf3d 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -361,6 +361,14 @@
return self.latest_revision.text
+ def _latest_cached_revision(self): + """Get the latest revision if cached and has text, otherwise None.""" + if (hasattr(self, '_revid') and self._revid in self._revisions and + self._revisions[self._revid].text is not None): + return self._revisions[self._revid] + else: + return None + def _getInternals(self, sysop): """Helper function for get().
@@ -374,9 +382,7 @@ raise self._getexception
# If not already stored, fetch revision - if not hasattr(self, "_revid") \ - or self._revid not in self._revisions \ - or self._revisions[self._revid].text is None: + if self._latest_cached_revision() is None: try: self.site.loadrevisions(self, getText=True, sysop=sysop) except (pywikibot.NoPage, pywikibot.SectionError) as e: @@ -439,6 +445,9 @@ @property def latest_revision(self): """Return the current revision for this page.""" + rev = self._latest_cached_revision() + if rev is not None: + return rev return next(self.revisions(content=True, total=1))
@property
pywikibot-commits@lists.wikimedia.org