Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(http): Rename useCache option to memCache #22300

Merged
merged 3 commits into from May 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 5 additions & 7 deletions lib/modules/platform/bitbucket-server/index.ts
Expand Up @@ -258,7 +258,7 @@ export async function getPr(

const res = await bitbucketServerHttp.getJson<BbsRestPr>(
`./rest/api/1.0/projects/${config.projectKey}/repos/${config.repositorySlug}/pull-requests/${prNo}`,
{ useCache: !refreshCache }
{ memCache: !refreshCache }
);

const pr: BbsPr = {
Expand Down Expand Up @@ -356,17 +356,15 @@ export async function refreshPr(number: number): Promise<void> {

async function getStatus(
branchName: string,
useCache = true
memCache = true
): Promise<utils.BitbucketCommitStatus> {
const branchCommit = git.getBranchCommit(branchName);

return (
await bitbucketServerHttp.getJson<utils.BitbucketCommitStatus>(
// TODO: types (#7154)
`./rest/build-status/1.0/commits/stats/${branchCommit!}`,
{
useCache,
}
{ memCache }
)
).body;
}
Expand Down Expand Up @@ -404,15 +402,15 @@ export async function getBranchStatus(

function getStatusCheck(
branchName: string,
useCache = true
memCache = true
): Promise<utils.BitbucketStatus[]> {
const branchCommit = git.getBranchCommit(branchName);

return utils.accumulateValues(
// TODO: types (#7154)
`./rest/build-status/1.0/commits/${branchCommit!}`,
'get',
{ useCache }
{ memCache }
);
}

Expand Down
6 changes: 3 additions & 3 deletions lib/modules/platform/bitbucket/index.ts
Expand Up @@ -80,7 +80,7 @@ export async function initPlatform({
setBaseUrl(defaults.endpoint);
renovateUserUuid = null;
const options: HttpOptions = {
useCache: false,
memCache: false,
};
if (token) {
options.token = token;
Expand Down Expand Up @@ -362,15 +362,15 @@ export async function getBranchPr(branchName: string): Promise<Pr | null> {

async function getStatus(
branchName: string,
useCache = true
memCache = true
): Promise<BitbucketStatus[]> {
const sha = await getBranchCommit(branchName);
return utils.accumulateValues<BitbucketStatus>(
// TODO: types (#7154)
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
`/2.0/repositories/${config.repository}/commit/${sha}/statuses`,
'get',
{ useCache }
{ memCache }
);
}
// Returns the combined status for a branch.
Expand Down
16 changes: 7 additions & 9 deletions lib/modules/platform/gitea/index.ts
Expand Up @@ -165,7 +165,7 @@ function getLabelList(): Promise<Label[]> {
if (config.labelList === null) {
const repoLabels = helper
.getRepoLabels(config.repository, {
useCache: false,
memCache: false,
})
.then((labels) => {
logger.debug(`Retrieved ${labels.length} repo labels`);
Expand All @@ -174,7 +174,7 @@ function getLabelList(): Promise<Label[]> {

const orgLabels = helper
.getOrgLabels(config.repository.split('/')[0], {
useCache: false,
memCache: false,
})
.then((labels) => {
logger.debug(`Retrieved ${labels.length} org labels`);
Expand Down Expand Up @@ -382,7 +382,7 @@ const platform: Platform = {

// Refresh caches by re-fetching commit status for branch
await helper.getCombinedCommitStatus(config.repository, branchName, {
useCache: false,
memCache: false,
});
} catch (err) {
logger.warn({ err }, 'Failed to set branch status');
Expand Down Expand Up @@ -449,7 +449,7 @@ const platform: Platform = {
getPrList(): Promise<Pr[]> {
if (config.prList === null) {
config.prList = helper
.searchPRs(config.repository, { state: 'all' }, { useCache: false })
.searchPRs(config.repository, { state: 'all' }, { memCache: false })
.then((prs) => {
const prList = prs.map(toRenovatePR).filter(is.truthy);
logger.debug(`Retrieved ${prList.length} Pull Requests`);
Expand Down Expand Up @@ -650,7 +650,7 @@ const platform: Platform = {
getIssueList(): Promise<Issue[]> {
if (config.issueList === null) {
config.issueList = helper
.searchIssues(config.repository, { state: 'all' }, { useCache: false })
.searchIssues(config.repository, { state: 'all' }, { memCache: false })
.then((issues) => {
const issueList = issues.map(toRenovateIssue);
logger.debug(`Retrieved ${issueList.length} Issues`);
Expand All @@ -661,12 +661,10 @@ const platform: Platform = {
return config.issueList;
},

async getIssue(number: number, useCache = true): Promise<Issue | null> {
async getIssue(number: number, memCache = true): Promise<Issue | null> {
try {
const body = (
await helper.getIssue(config.repository, number, {
useCache,
})
await helper.getIssue(config.repository, number, { memCache })
).body;
return {
number,
Expand Down
12 changes: 8 additions & 4 deletions lib/modules/platform/github/index.ts
Expand Up @@ -743,7 +743,7 @@ async function ensureBranchSha(branchName: string, sha: string): Promise<void> {

let branchExists = false;
try {
await githubApi.head(refUrl, { useCache: false });
await githubApi.head(refUrl, { memCache: false });
branchExists = true;
} catch (err) {
if (err.statusCode !== 404) {
Expand Down Expand Up @@ -836,7 +836,9 @@ async function getStatus(
)}/status`;

return (
await githubApi.getJson<CombinedBranchStatus>(commitStatusUrl, { useCache })
await githubApi.getJson<CombinedBranchStatus>(commitStatusUrl, {
memCache: useCache,
})
).body;
}

Expand Down Expand Up @@ -951,7 +953,9 @@ async function getStatusCheck(

const url = `repos/${config.repository}/commits/${branchCommit}/statuses`;

return (await githubApi.getJson<GhBranchStatus[]>(url, { useCache })).body;
return (
await githubApi.getJson<GhBranchStatus[]>(url, { memCache: useCache })
).body;
}

interface GithubToRenovateStatusMapping {
Expand Down Expand Up @@ -1077,7 +1081,7 @@ export async function getIssue(
const issueBody = (
await githubApi.getJson<{ body: string }>(
`repos/${config.parentRepo ?? config.repository}/issues/${number}`,
{ useCache }
{ memCache: useCache }
)
).body.body;
return {
Expand Down
6 changes: 3 additions & 3 deletions lib/modules/platform/gitlab/index.ts
Expand Up @@ -371,7 +371,7 @@ async function getStatus(
return (
await gitlabApi.getJson<GitlabBranchStatus[]>(url, {
paginate: true,
useCache,
memCache: useCache,
})
).body;
} catch (err) /* istanbul ignore next */ {
Expand Down Expand Up @@ -864,7 +864,7 @@ export async function getIssueList(): Promise<GitlabIssue[]> {
const res = await gitlabApi.getJson<
{ iid: number; title: string; labels: string[] }[]
>(`projects/${config.repository}/issues?${query}`, {
useCache: false,
memCache: false,
paginate: true,
});
// istanbul ignore if
Expand All @@ -889,7 +889,7 @@ export async function getIssue(
const issueBody = (
await gitlabApi.getJson<{ description: string }>(
`projects/${config.repository}/issues/${number}`,
{ useCache }
{ memCache: useCache }
)
).body.description;
return {
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/platform/types.ts
Expand Up @@ -165,7 +165,7 @@ export type EnsureIssueResult = 'updated' | 'created';
export interface Platform {
findIssue(title: string): Promise<Issue | null>;
getIssueList(): Promise<Issue[]>;
getIssue?(number: number, useCache?: boolean): Promise<Issue | null>;
getIssue?(number: number, memCache?: boolean): Promise<Issue | null>;
getVulnerabilityAlerts?(): Promise<VulnerabilityAlert[]>;
getRawFile(
fileName: string,
Expand Down
15 changes: 8 additions & 7 deletions lib/util/http/index.ts
Expand Up @@ -163,11 +163,12 @@ export class Http<Opts extends HttpOptions = HttpOptions> {
]);
let resPromise: Promise<HttpResponse<T>> | null = null;

// Cache GET requests unless useCache=false
if (
(options.method === 'get' || options.method === 'head') &&
options.useCache !== false
) {
// Cache GET requests unless memCache=false
const useMemCache =
options.memCache !== false &&
(options.method === 'get' || options.method === 'head');

if (useMemCache) {
resPromise = memCache.get(cacheKey);
}

Expand Down Expand Up @@ -195,8 +196,8 @@ export class Http<Opts extends HttpOptions = HttpOptions> {

resPromise = queuedTask();

if (options.method === 'get' || options.method === 'head') {
memCache.set(cacheKey, resPromise); // always set if it's a get or a head
if (useMemCache) {
memCache.set(cacheKey, resPromise);
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/util/http/types.ts
Expand Up @@ -19,7 +19,7 @@ export type GotExtraOptions = {
token?: string;
hostType?: string;
enabled?: boolean;
useCache?: boolean;
memCache?: boolean;
noAuth?: boolean;
context?: GotContextOptions;
};
Expand Down Expand Up @@ -62,7 +62,7 @@ export interface HttpOptions {
throwHttpErrors?: boolean;

token?: string;
useCache?: boolean;
memCache?: boolean;
}

export interface InternalHttpOptions extends HttpOptions {
Expand Down