jenkins-bot merged this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
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(-)

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

To view, visit change 441011. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib5275be8bd8cca7b8f211b137646da613f371328
Gerrit-Change-Number: 441011
Gerrit-PatchSet: 1
Gerrit-Owner: Dalba <dalba.wiki@gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: Zoranzoki21 <zorandori4444@gmail.com>
Gerrit-Reviewer: jenkins-bot