Skip to content

Commit

Permalink
feat: added an additional sharding key
Browse files Browse the repository at this point in the history
  • Loading branch information
Arvi3d committed Oct 18, 2021
1 parent 5f8c641 commit 8b1f07d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/analysis.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-await-in-loop */
import omit from 'lodash.omit';

import { AnalyzeFoldersOptions, prepareExtendingBundle, resolveBundleFilePath } from './files';
import { AnalyzeFoldersOptions, prepareExtendingBundle, resolveBundleFilePath, calcHash } from './files';
import { POLLING_INTERVAL } from './constants';
import {
GetAnalysisErrorCodes,
Expand Down Expand Up @@ -111,6 +111,7 @@ export async function analyzeFolders(options: FileAnalysisOptions): Promise<File
bundleHash: fileBundle.bundleHash,
...options.connection,
...options.analysisOptions,
shard: calcHash(fileBundle.baseDir),
});

if (analysisResults.type === 'legacy') {
Expand Down Expand Up @@ -301,6 +302,7 @@ export async function extendAnalysis(options: ExtendAnalysisOptions): Promise<Fi
bundleHash: remoteBundle.bundleHash,
...options.connection,
...options.analysisOptions,
shard: calcHash(fileBundle.baseDir),
limitToFiles,
});

Expand Down
8 changes: 4 additions & 4 deletions src/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,10 @@ export function getBundleFilePath(filePath: string, baseDir: string) {
return encodeURI(posixPath);
}

export function calcHash(content: string): string {
return crypto.createHash(HASH_ALGORITHM).update(content).digest(ENCODE_TYPE);
};

export async function getFileInfo(
filePath: string,
baseDir: string,
Expand All @@ -369,10 +373,6 @@ export async function getFileInfo(

const bundlePath = getBundleFilePath(filePath, baseDir);

const calcHash = (content: string) => {
return crypto.createHash(HASH_ALGORITHM).update(content).digest(ENCODE_TYPE);
};

let fileContent = '';
let fileHash = '';
if (!withContent && !!cache) {
Expand Down
2 changes: 2 additions & 0 deletions src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ const GET_ANALYSIS_ERROR_MESSAGES: { [P in GetAnalysisErrorCodes]: string } = {
};

export interface AnalysisOptions {
readonly shard?: string;
readonly severity?: number;
readonly limitToFiles?: string[];
readonly prioritized?: boolean;
Expand All @@ -407,6 +408,7 @@ export async function getAnalysis(
type: 'file',
hash: options.bundleHash,
limitToFiles: options.limitToFiles || [],
...(options.shard ? {shard: options.shard} : null),
},
...pick(options, ['severity', 'prioritized', 'legacy']),
},
Expand Down

0 comments on commit 8b1f07d

Please sign in to comment.