Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2bb115c

Browse files
committed
Implement nested four-level cache
Prevents putting too many files in a single folder
1 parent 00ec4ec commit 2bb115c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/matplotlib/texmanager.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,17 @@ def get_basefile(cls, tex, fontsize, dpi=None):
176176
Return a filename based on a hash of the string, fontsize, and dpi.
177177
"""
178178
src = cls._get_tex_source(tex, fontsize) + str(dpi)
179+
filehash = hashlib.md5(src.encode('utf-8')).hexdigest()
180+
181+
nested_folders = Path()
182+
for i in range(0, 8, 2): # 4-level 2-letter dirs
183+
nested_folders = nested_folders / Path(filehash[i:i+2])
184+
185+
filepath = (Path(cls.texcache) / nested_folders)
186+
filepath.mkdir(parents=True, exist_ok=True)
187+
179188
return os.path.join(
180-
cls.texcache, hashlib.md5(src.encode('utf-8')).hexdigest())
189+
os.path.join(cls.texcache, nested_folders), filehash)
181190

182191
@classmethod
183192
def get_font_preamble(cls):

0 commit comments

Comments
 (0)