Files
Jamie Tanna f932d52fbd feat(platform): get all branch update dates in a more performant manner (#44582)
* feat(platform): get all branch update dates in a more performant manner

When Renovate is working on a repository with many /potential/ branches,
as well as some actually created branches, it's possible for the
calculation for `commitHourlyLimit` to end up taking significant time.

This can lead to a less performant job generally, but can sometimes lead
to the Renovate job failing to complete, and then timing out when
executed by a job runner.

To handle this, we can instead use use `git for-each-ref` to look up
each Git ref (remotely) and request the commit date, which leads to a
much more performant lookup.

Co-authored-by: Claude Sonnet 5 <jamie.tanna+claude-code@mend.io>

* fixup! feat(platform): get all branch update dates in a more performant manner

Co-authored-by: Claude Sonnet 5 <jamie.tanna+claude-code@mend.io>

* fixup! Merge remote-tracking branch 'origin/HEAD' into wip/commit-hourly-slow

---------

Co-authored-by: Claude Sonnet 5 <jamie.tanna+claude-code@mend.io>
2026-07-21 13:17:58 +00:00

74 lines
2.2 KiB
TypeScript

import { glob } from 'glob';
import type { DateTime } from 'luxon';
import { logger } from '../../../logger/index.ts';
import { rawExec } from '../../../util/exec/common.ts';
import type { CommitFilesConfig } from '../../../util/git/types.ts';
import type { LongCommitSha } from '../../../util/schema-utils/git.ts';
import type { PlatformScm } from '../types.ts';
let fileList: string[] | undefined;
export class LocalFs implements PlatformScm {
isBranchBehindBase(
_branchName: string,
_baseBranch: string,
): Promise<boolean> {
return Promise.resolve(false);
}
isBranchModified(_branchName: string, _baseBranch: string): Promise<boolean> {
return Promise.resolve(false);
}
isBranchConflicted(_baseBranch: string, _branch: string): Promise<boolean> {
return Promise.resolve(false);
}
branchExists(_branchName: string): Promise<boolean> {
return Promise.resolve(true);
}
getBranchCommit(_branchName: string): Promise<LongCommitSha | null> {
return Promise.resolve(null);
}
getBranchUpdateDate(_branchName: string): Promise<DateTime | null> {
return Promise.resolve(null);
}
getAllBranchUpdateDates(): Promise<Record<string, DateTime>> {
return Promise.resolve({});
}
deleteBranch(_branchName: string): Promise<void> {
return Promise.resolve();
}
commitAndPush(
_commitConfig: CommitFilesConfig,
): Promise<LongCommitSha | null> {
return Promise.resolve(null);
}
async getFileList(): Promise<string[]> {
try {
// fetch file list using git
const maxBuffer = 10 * 1024 * 1024; // 10 MiB in bytes
const stdout = (await rawExec('git ls-files', { maxBuffer })).stdout;
logger.debug('Got file list using git');
fileList = stdout.split('\n');
} catch {
logger.debug('Could not get file list using git, using glob instead');
fileList ??= await glob('**', {
dot: true,
nodir: true,
});
}
return fileList;
}
checkoutBranch(_branchName: string): Promise<LongCommitSha | null> {
return Promise.resolve(null);
}
mergeAndPush(_branchName: string): Promise<void> {
return Promise.resolve();
}
mergeToLocal(_branchName: string): Promise<void> {
return Promise.resolve();
}
}