Skip to content

Commit

Permalink
fix: rate-limit issue if changed filters is huge
Browse files Browse the repository at this point in the history
  • Loading branch information
piquark6046 committed Feb 17, 2024
1 parent 1f0230b commit 0903a96
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 0 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,8 @@ for (const Branch of Branches) {
// Hold until checking hash is done.
performance.mark('githubrawhash')
const GitHubRAWHashInstance = new GitHubRAWHash(ProgramOptions, ChangedFiles, Branches)
Actions.startGroup('Checking hashes logs')
await GitHubRAWHashInstance.Register()
await GitHubRAWHashInstance.Check()
Actions.endGroup()
Actions.info(`Checking hashes took ${Math.floor(performance.measure('githubrawhash-duration', 'githubrawhash').duration)} ms.`)

performance.mark('purge')
Expand Down
8 changes: 5 additions & 3 deletions sources/hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ export class GitHubRAWHash {
}

async Check() {
if (this.GitHubRAWHashMap.size > 15) {
Actions.warning('The number of changed files is over 15. It may take a long time to check the hash. Skipped.')
return
}

const PromiseList: Array<Promise<void>> = []
for (const ChangedFile of this.ChangedFiles.filter(ChangedFile => ChangedFile.Branch !== 'latest')) {
// eslint-disable-next-line no-async-promise-executor
Expand All @@ -64,12 +69,9 @@ export class GitHubRAWHash {
// eslint-disable-next-line no-await-in-loop
const Uint8Data = await GetFileFromGitHubRAW(this.ProgramOptions, ChangedFile.Branch, ChangedFile.Filename)
if (GetSHA3FromUint8Array(Uint8Data) === this.GitHubRAWHashMap.get(JSON.stringify({Branch: ChangedFile.Branch, Filename: ChangedFile.Filename}))) {
Actions.info(`OK: Hash of ${ChangedFile.Filename} in ${ChangedFile.Branch} is ${GetSHA3FromUint8Array(Uint8Data)}`)
break
}

Actions.info(`Retrying: Hash of ${ChangedFile.Filename} in ${ChangedFile.Branch} is ${GetSHA3FromUint8Array(Uint8Data)}`)

// eslint-disable-next-line no-await-in-loop
await new Promise(Resolve => {
setTimeout(Resolve, 500)
Expand Down

0 comments on commit 0903a96

Please sign in to comment.