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

Change subject: page: Load only current revision ID
......................................................................

page: Load only current revision ID

Use the current-revision load path when the latest revision ID is not cached.

Avoid retrieving and caching the complete page history for a single ID.

Change-Id: Ibea2be0531c4de4ef56b9812e8fa98fc185dba72
---
M pywikibot/page/_basepage.py
M tests/page_tests.py
2 files changed, 21 insertions(+), 1 deletion(-)

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




diff --git a/pywikibot/page/_basepage.py b/pywikibot/page/_basepage.py
index 9ebfc4f..a6d65e5 100644
--- a/pywikibot/page/_basepage.py
+++ b/pywikibot/page/_basepage.py
@@ -508,7 +508,7 @@
     def latest_revision_id(self):
         """Return the current revision id for this page."""
         if not hasattr(self, '_revid'):
-            self.revisions()
+            self.site.loadrevisions(self)
         return self._revid

     @latest_revision_id.deleter
diff --git a/tests/page_tests.py b/tests/page_tests.py
index 0c06c81..f0e3769 100755
--- a/tests/page_tests.py
+++ b/tests/page_tests.py
@@ -207,6 +207,26 @@
             revid=1, slots={'main': {'*': text}})
         return page

+    def test_latest_revision_id_loads_current_revision(self) -> None:
+        """Test loading and caching the latest revision ID."""
+        page = pywikibot.Page(self.site, 'Test page')
+        revision = pywikibot.page.Revision(revid=123)
+
+        def loadrevisions(loaded_page) -> None:
+            loaded_page._revisions[revision.revid] = revision
+            loaded_page.latest_revision_id = revision.revid
+
+        with mock.patch.object(
+                self.site, 'loadrevisions',
+                side_effect=loadrevisions) as loadrevisions:
+            self.assertEqual(page.latest_revision_id, revision.revid)
+            self.assertEqual(page.latest_revision_id, revision.revid)
+
+        loadrevisions.assert_called_once_with(page)
+        self.assertEqual(list(page._revisions), [revision.revid])
+        self.assertIs(page._revisions[revision.revid], revision)
+        self.assertIsNone(revision.text)
+
     def test_get_does_not_validate_section(self) -> None:
         """Test that get does not inspect a title section."""
         text = '== Existing ==\nText'

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