From da0452b10c3468405a0ff75c67839add0892a600 Mon Sep 17 00:00:00 2001 From: tdurieux Date: Thu, 26 Jan 2023 13:51:38 +0100 Subject: [PATCH] fix: improve performance PRs --- src/PullRequest.ts | 94 +++++++++++++++++++--------------------------- 1 file changed, 38 insertions(+), 56 deletions(-) diff --git a/src/PullRequest.ts b/src/PullRequest.ts index be379f8..280c452 100644 --- a/src/PullRequest.ts +++ b/src/PullRequest.ts @@ -39,38 +39,20 @@ export default class PullRequest { const octokit = new Octokit({ auth }); const [owner, repo] = this._model.source.repositoryFullName.split("/"); const pull_number = this._model.source.pullRequestId; - const prInfo = await octokit.rest.pulls.get({ - owner, - repo, - pull_number, - }); - - prInfo.data.updated_at; - prInfo.data.draft; - prInfo.data.merged; - prInfo.data.merged_at; - prInfo.data.state; - prInfo.data.base.repo.full_name; - prInfo.data.head.repo.full_name; - const comments = await octokit.rest.issues.listComments({ - owner, - repo, - issue_number: pull_number, - per_page: 100, - }); - // const commits = await octokit.rest.pulls.listCommits({ - // owner, - // repo, - // pull_number, - // per_page: 100, - // }); - // const files = await octokit.rest.pulls.listFiles({ - // owner, - // repo, - // pull_number, - // per_page: 100, - // }); - const diff = await got(prInfo.data.diff_url); + const [prInfo, comments, diff] = await Promise.all([ + octokit.rest.pulls.get({ + owner, + repo, + pull_number, + }), + octokit.rest.issues.listComments({ + owner, + repo, + issue_number: pull_number, + per_page: 100, + }), + got(`https://github.com/${owner}/${repo}/pull/${pull_number}.diff`), + ]); this._model.pullRequest = { diff: diff.body, title: prInfo.data.title, @@ -140,10 +122,10 @@ export default class PullRequest { yesterday.setDate(yesterday.getDate() - 1); if ( opt?.force || - (this._model.options.update && this._model.lastView < yesterday) + (this._model.options.update && this._model.anonymizeDate < yesterday) ) { await this.download(); - this._model.lastView = new Date(); + this._model.anonymizeDate = new Date(); await this._model.save(); } } @@ -225,28 +207,6 @@ export default class PullRequest { return null; } - /***** Getters ********/ - - get pullRequestId() { - return this._model.pullRequestId; - } - - get options() { - return this._model.options; - } - - get source() { - return this._model.source; - } - - get model() { - return this._model; - } - - get status() { - return this._model.status; - } - content() { const output: any = { anonymizeDate: this._model.anonymizeDate, @@ -288,6 +248,28 @@ export default class PullRequest { return output; } + /***** Getters ********/ + + get pullRequestId() { + return this._model.pullRequestId; + } + + get options() { + return this._model.options; + } + + get source() { + return this._model.source; + } + + get model() { + return this._model; + } + + get status() { + return this._model.status; + } + toJSON() { return { pullRequestId: this._model.pullRequestId,