2
0
mirror of https://github.com/xcat2/confluent.git synced 2026-01-11 10:32:31 +00:00

Speed up log initialization

Cache the directory list over a few seconds
to avoid excessive filesystem calls.

Also switchg to a more potent regex to avoid wasting time on timestamped files.
This commit is contained in:
Jarrod Johnson
2025-08-08 15:51:45 -04:00
parent a1cf8023c6
commit e01701bcf1

View File

@@ -386,14 +386,18 @@ class TimedAndSizeRotatingFileHandler(BaseRotatingHandler):
f['time'] in t_list[:-(self.backupCount - 1)]]
return result
dirContents = {}
def initSizeRollingCount(self):
"""
Init the max number of log files for current time.
"""
dirName, baseName = os.path.split(self.textpath)
prefix = baseName + "."
filePaths = glob.glob(os.path.join(dirName, "%s*" % prefix))
fileNames = [os.path.split(f)[1] for f in filePaths]
if dirName not in self.dirContents or self.dirContents[dirName][1] < time.time():
self.dirContents[dirName] = (os.listdir(dirName), time.time() + 5)
matchexp = re.compile(f'^{prefix}\.\d+$')
fileNames = [f for f in self.dirContents[dirName][0]
if matchexp.match(f)]
plen = len(prefix)
for fileName in fileNames:
suffix = fileName[plen:]