Skip to content

Commit

Permalink
feat(bitbucket): Enable HTTP cache for PR list and json fetch (#28024)
Browse files Browse the repository at this point in the history
  • Loading branch information
zharinov committed Mar 19, 2024
1 parent 0dfea67 commit fcffdc9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/modules/platform/bitbucket/index.ts
Expand Up @@ -7,6 +7,7 @@ import { parseJson } from '../../../util/common';
import * as git from '../../../util/git';
import * as hostRules from '../../../util/host-rules';
import { BitbucketHttp, setBaseUrl } from '../../../util/http/bitbucket';
import { repoCacheProvider } from '../../../util/http/cache/repository-http-cache-provider';
import type { HttpOptions } from '../../../util/http/types';
import { regEx } from '../../../util/regex';
import { sanitize } from '../../../util/sanitize';
Expand Down Expand Up @@ -163,7 +164,10 @@ export async function getRawFile(
`/2.0/repositories/${repo}/src/` +
(finalBranchOrTag ?? `HEAD`) +
`/${path}`;
const res = await bitbucketHttp.get(url);
const res = await bitbucketHttp.get(url, {
cacheProvider: repoCacheProvider,
memCache: true,
});
return res.body;
}

Expand Down
2 changes: 2 additions & 0 deletions lib/modules/platform/bitbucket/pr-cache.spec.ts
Expand Up @@ -74,6 +74,7 @@ describe('modules/platform/bitbucket/pr-cache', () => {
},
]);
expect(cache).toEqual({
httpCache: {},
platform: {
bitbucket: {
pullRequestsCache: {
Expand Down Expand Up @@ -120,6 +121,7 @@ describe('modules/platform/bitbucket/pr-cache', () => {
{ number: 2, title: 'title' },
]);
expect(cache).toEqual({
httpCache: {},
platform: {
bitbucket: {
pullRequestsCache: {
Expand Down
7 changes: 6 additions & 1 deletion lib/modules/platform/bitbucket/pr-cache.ts
Expand Up @@ -4,6 +4,7 @@ import { logger } from '../../../logger';
import * as memCache from '../../../util/cache/memory';
import { getCache } from '../../../util/cache/repository';
import type { BitbucketHttp } from '../../../util/http/bitbucket';
import { repoCacheProvider } from '../../../util/http/cache/repository-http-cache-provider';
import type { Pr } from '../types';
import type { BitbucketPrCacheData, PagedResult, PrResponse } from './types';
import { prFieldsFilter, prInfo, prStates } from './utils';
Expand Down Expand Up @@ -128,7 +129,11 @@ export class BitbucketPrCache {
private async sync(http: BitbucketHttp): Promise<BitbucketPrCache> {
logger.debug('Syncing PR list');
const url = this.getUrl();
const opts = { paginate: true, pagelen: 50 };
const opts = {
paginate: true,
pagelen: 50,
cacheProvider: repoCacheProvider,
};
const res = await http.getJson<PagedResult<PrResponse>>(url, opts);
this.reconcile(res.body.values);
return this;
Expand Down

0 comments on commit fcffdc9

Please sign in to comment.