John Vandenberg has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/176007

Change subject: mediawiki_messages reuses QueryGenerator
......................................................................

mediawiki_messages reuses QueryGenerator

When mediawiki_messages is called with a specific set of keys requested,
it inefficiently and incorrectly iterates the generator for each key.
This breaks a fundamental assumption of a 'generator' - that it can not
be re-used.  It is assuming that QueryGenerator was able to fetch all
the requested messages without continuation, as only the last fetch
will exist in QueryGenerator.data after the first iteration is complete.

Change-Id: Ia50ec73d33caa548227dfcbd52119117720787dc
---
M pywikibot/site.py
1 file changed, 9 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/07/176007/1

diff --git a/pywikibot/site.py b/pywikibot/site.py
index d83a098..bca8612 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -1831,22 +1831,19 @@
                 amlang=self.lang,
             )
 
+            for msg in msg_query:
+                if 'missing' not in msg:
+                    self._msgcache[msg['name']] = msg['*']
+
             # Return all messages
             if keys == u'*' or keys == [u'*']:
-                for msg in msg_query:
-                    if 'missing' not in msg:
-                        self._msgcache[msg['name']] = msg['*']
                 return self._msgcache
-            # Return only given keys
             else:
-                for _key in keys:
-                    for msg in msg_query:
-                        if msg['name'] == _key and 'missing' not in msg:
-                            self._msgcache[_key] = msg['*']
-                            break
-                    else:
-                        raise KeyError("Site %(self)s has no message 
'%(_key)s'"
-                                       % locals())
+                # Check requested keys
+                for key in keys:
+                    if key not in self._msgcache:
+                        raise KeyError("Site %s has no message '%s'"
+                                       % (self, key))
 
         return dict((_key, self._msgcache[_key]) for _key in keys)
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia50ec73d33caa548227dfcbd52119117720787dc
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <[email protected]>

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

Reply via email to