jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/376058 )

Change subject: [IMPR] Cache fetched Wikibase item
......................................................................


[IMPR] Cache fetched Wikibase item

Repetitive ItemPage.fromPage calls always create
a new instance. When using -onlyif(not) filters,
the item's content can be fetched during filtering
and during treating.

Change-Id: I5b5b4d69da32c311f7d5ffe7d1767bc31e73b295
---
M pywikibot/page.py
1 file changed, 8 insertions(+), 3 deletions(-)

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



diff --git a/pywikibot/page.py b/pywikibot/page.py
index c03c878..d54be98 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -163,7 +163,7 @@
         '_contentmodel', '_langlinks', '_isredir', '_coords',
         '_preloadedtext', '_timestamp', '_applicable_protections',
         '_flowinfo', '_quality', '_pageprops', '_revid', '_quality_text',
-        '_pageimage'
+        '_pageimage', '_item'
     )
 
     def __init__(self, source, title=u"", ns=0):
@@ -4178,6 +4178,8 @@
         @raise NoPage: There is no corresponding ItemPage for the page
         @raise WikiBaseError: The site of the page has no data repository.
         """
+        if hasattr(page, '_item'):
+            return page._item
         if not page.site.has_data_repository:
             raise pywikibot.WikiBaseError('{0} has no data repository'
                                           ''.format(page.site))
@@ -4189,7 +4191,8 @@
                    '_pageprops') and page.properties().get('wikibase_item'):
             # If we have already fetched the pageprops for something else,
             # we already have the id, so use it
-            return cls(repo, page.properties().get('wikibase_item'))
+            page._item = cls(repo, page.properties().get('wikibase_item'))
+            return page._item
         i = cls(repo)
         # clear id, and temporarily store data needed to lazy loading the item
         del i.id
@@ -4197,7 +4200,8 @@
         i._title = page.title(withSection=False)
         if not lazy_load and not i.exists():
             raise pywikibot.NoPage(i)
-        return i
+        page._item = i
+        return page._item
 
     @classmethod
     def from_entity_uri(cls, site, uri, lazy_load=False):
@@ -4309,6 +4313,7 @@
         for dbname in self.sitelinks:
             pg = Page(pywikibot.site.APISite.fromDBName(dbname),
                       self.sitelinks[dbname])
+            pg._item = self
             if family is None or family == pg.site.family:
                 yield pg
 

-- 
To view, visit https://gerrit.wikimedia.org/r/376058
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I5b5b4d69da32c311f7d5ffe7d1767bc31e73b295
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Matěj Suchánek <[email protected]>
Gerrit-Reviewer: Dalba <[email protected]>
Gerrit-Reviewer: John Vandenberg <[email protected]>
Gerrit-Reviewer: Magul <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to