mirror of
https://github.com/PR0M3TH3AN/TORCH.git
synced 2026-10-27 07:51:52 +00:00
Merge pull request #242 from PR0M3TH3AN/scheduler-cycle-optimization-6566135138689301144
⚡ Optimize scheduler cycle log reading performance
This commit is contained in:
2 files changed
+20
-1425
No files matched your search
@@ -365,22 +365,28 @@ async function getLatestFile(logDir) {
|
||||
.filter((filename) => isStrictSchedulerLogFilename(filename))
|
||||
.sort((a, b) => b.localeCompare(a));
|
||||
|
||||
const results = await Promise.all(
|
||||
files.map(async (filename) => {
|
||||
const filePath = path.join(logDir, filename);
|
||||
const content = await fs.readFile(filePath, 'utf8').catch(() => '');
|
||||
const createdAtMs = parseDateValue(parseFrontmatterCreatedAt(content));
|
||||
const fileTimestampMs = parseTimestampFromFilename(filename);
|
||||
const effectiveMs = createdAtMs ?? fileTimestampMs;
|
||||
|
||||
if (!effectiveMs) {
|
||||
console.warn(`[scheduler] Ignoring invalid log timestamp in ${filename}; checking next candidate.`);
|
||||
return null;
|
||||
}
|
||||
return { filename, effectiveMs };
|
||||
}),
|
||||
);
|
||||
|
||||
let latest = null;
|
||||
|
||||
for (const filename of files) {
|
||||
const filePath = path.join(logDir, filename);
|
||||
const content = await fs.readFile(filePath, 'utf8').catch(() => '');
|
||||
const createdAtMs = parseDateValue(parseFrontmatterCreatedAt(content));
|
||||
const fileTimestampMs = parseTimestampFromFilename(filename);
|
||||
const effectiveMs = createdAtMs ?? fileTimestampMs;
|
||||
|
||||
if (!effectiveMs) {
|
||||
console.warn(`[scheduler] Ignoring invalid log timestamp in ${filename}; checking next candidate.`);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!latest || effectiveMs > latest.effectiveMs) {
|
||||
latest = { filename, effectiveMs };
|
||||
for (const result of results) {
|
||||
if (!result) continue;
|
||||
if (!latest || result.effectiveMs > latest.effectiveMs) {
|
||||
latest = result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user