jenkins-bot has submitted this change and it was merged.
Change subject: Deprecate ParamInfo.query_modules_with_limits
......................................................................
Deprecate ParamInfo.query_modules_with_limits
query_modules_with_limits is an unnecessary performance hit
during site initialisation, and causes problems in production
when there are problems with a query module.
It also causes a paraminfo caching bug to become a major bug
preventing all access due to an assert added in 424eaa3.
Bug: T100779
Bug: T109168
Change-Id: I90910e52395f1db72f51088fa4306f62b625cc2c
---
M pywikibot/data/api.py
M tests/api_tests.py
M tests/utils.py
3 files changed, 29 insertions(+), 8 deletions(-)
Approvals:
XZise: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index f3772c7..e3e5a8a 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -1034,6 +1034,7 @@
if self[mod][attribute])
@property
+ @deprecated('parameter()')
def query_modules_with_limits(self):
"""Set of all query modules which have limits."""
if not self._with_limits:
@@ -2467,10 +2468,11 @@
parameters['continue'] = True
self.request = self.request_class(**kwargs)
- # This forces all paraminfo for all query modules to be bulk loaded.
- limited_modules = (
- set(self.modules) & self.site._paraminfo.query_modules_with_limits
- )
+ self.site._paraminfo.fetch('query+' + mod for mod in self.modules)
+
+ limited_modules = set(
+ mod for mod in self.modules
+ if self.site._paraminfo.parameter('query+' + mod, 'limit'))
if not limited_modules:
self.limited_module = None
@@ -2481,7 +2483,7 @@
# Query will continue as needed until limit (if any) for this module
# is reached.
for module in self.modules:
- if module in self.site._paraminfo.query_modules_with_limits:
+ if module in limited_modules:
self.limited_module = module
limited_modules.remove(module)
break
diff --git a/tests/api_tests.py b/tests/api_tests.py
index 6cb0c83..586e15f 100644
--- a/tests/api_tests.py
+++ b/tests/api_tests.py
@@ -468,6 +468,19 @@
self.assertFalse(other_modules & pi.modules)
+class TestParaminfoModules(DefaultSiteTestCase):
+
+ """Test loading all paraminfo modules."""
+
+ def test_action_modules(self):
+ """Test loading all action modules."""
+ self.site._paraminfo.fetch(self.site._paraminfo.action_modules)
+
+ def test_query_modules(self):
+ """Test loading all query modules."""
+ self.site._paraminfo.fetch(self.site._paraminfo.query_modules)
+
+
class TestOptionSet(TestCase):
"""OptionSet class test class."""
diff --git a/tests/utils.py b/tests/utils.py
index 79a9244..a08b30e 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -243,14 +243,20 @@
self.prefixes = set()
def fetch(self, modules, _init=False):
- """Prevented method."""
- raise Exception(u'DryParamInfo.fetch(%r, %r) prevented'
- % (modules, _init))
+ """Load dry data."""
+ return [self[mod] for mod in modules]
def parameter(self, module, param_name):
"""Load dry data."""
return self[module][param_name]
+ def __getitem__(self, name):
+ """Return dry data or a dummy parameter block."""
+ try:
+ return super(DryParamInfo, self).__getitem__(name)
+ except KeyError:
+ return {'name': name, 'limit': None}
+
class DummySiteinfo():
--
To view, visit
https://gerrit.wikimedia.org/r/236246
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I90910e52395f1db72f51088fa4306f62b625cc2c
Gerrit-PatchSet: 4
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>