Skip to content

Commit

Permalink
fix(github): fix UND_ERR_CONNECT_TIMEOUT error (#606)
Browse files Browse the repository at this point in the history
* feat(processPages): add PAGE_PROCESS_CONCURRENCY env

* feat(github): add user login cache
  • Loading branch information
Feverqwe committed Nov 22, 2023
1 parent ff1601b commit d196861
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,6 @@ export const REGEXP_AUTHOR = /(?<=author:\s).+(?=\r?\n)/g;

export const MIN_CHUNK_SIZE = Number(process.env.MIN_CHUNK_SIZE) || 1000;
export const WORKERS_COUNT = Number(process.env.WORKERS_COUNT) || os.cpus().length - 1;
export const PAGE_PROCESS_CONCURRENCY = Number(process.env.PAGE_PROCESS_CONCURRENCY) || 500;

export const metadataBorder = '---';
11 changes: 8 additions & 3 deletions src/steps/processPages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ import {
} from '../models';
import {VCSConnector} from '../vcs-connector/connector-models';
import {getVCSConnector} from '../vcs-connector';
import {Lang, ResourceType, SINGLE_PAGE_DATA_FILENAME, SINGLE_PAGE_FILENAME} from '../constants';
import {
Lang,
PAGE_PROCESS_CONCURRENCY,
ResourceType,
SINGLE_PAGE_DATA_FILENAME,
SINGLE_PAGE_FILENAME,
} from '../constants';

const singlePageResults: Record<string, SinglePageResult[]> = {};
const singlePagePaths: Record<string, Set<string>> = {};
Expand All @@ -46,11 +52,10 @@ export async function processPages(outputBundlePath: string): Promise<void> {
PluginService.setPlugins();

const navigationPaths = TocService.getNavigationPaths();
const concurrency = 500;

await mapLimit(
navigationPaths,
concurrency,
PAGE_PROCESS_CONCURRENCY,
asyncify(async (pathToFile: string) => {
const pathData = getPathData(
pathToFile,
Expand Down
31 changes: 19 additions & 12 deletions src/vcs-connector/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const authorByGitEmail: Map<string, Contributor | null> = new Map();
const authorByPath: Map<string, Contributor | null> = new Map();
const contributorsByPath: Map<string, FileContributors> = new Map();
const contributorsData: Map<string, Contributor | null> = new Map();
const loginUserMap: Map<string, Contributor | null> = new Map();

async function getGitHubVCSConnector(): Promise<VCSConnector | undefined> {
const {contributors} = ArgvService.getConfig();
Expand Down Expand Up @@ -277,21 +278,27 @@ async function getFileContributorsByPath(path: string): Promise<FileContributors
}

async function getUserByLogin(octokit: Octokit, userLogin: string): Promise<Contributor | null> {
const user = await github.getRepoUser(octokit, userLogin);
let result = loginUserMap.get(userLogin);
if (!result) {
const user = await github.getRepoUser(octokit, userLogin);
if (!user) {
return null;
}

if (!user) {
return null;
}
const {avatar_url: avatar, html_url: url, email, login, name} = user;

const {avatar_url: avatar, html_url: url, email, login, name} = user;
result = {
avatar,
email,
login,
name,
url,
};

return {
avatar,
email,
login,
name,
url,
};
loginUserMap.set(userLogin, result);
}

return result;
}

function addNestedContributorsForPathFunction(
Expand Down

0 comments on commit d196861

Please sign in to comment.