jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/441011 )
Change subject: api.py: Cache the result of _get_cache_dir ......................................................................
api.py: Cache the result of _get_cache_dir
_get_cache_dir gets called on every CachedRequest.submit() and it involved a disk access in _make_dir function. Disk access is slow and does not seem necessary for every submit.
- Cache the result of _get_cache_dir by letting it overwrite itself on first call.
The downside is that users no longer will be able to change the cache directory dynamically by changing pywikibot.config2.base_dir value, but I don't see why anyone would want to do that. Therefore, hopefully, this minor change will not break any code.
Change-Id: Ib5275be8bd8cca7b8f211b137646da613f371328 --- M pywikibot/data/api.py 1 file changed, 1 insertion(+), 0 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py index de17ab5..8d7d3c1 100644 --- a/pywikibot/data/api.py +++ b/pywikibot/data/api.py @@ -2262,6 +2262,7 @@ path = os.path.join(pywikibot.config2.base_dir, 'apicache-py{0:d}'.format(PYTHON_VERSION[0])) cls._make_dir(path) + cls._get_cache_dir = classmethod(lambda c: path) # cache the result return path
@staticmethod