Skip to content

Commit

Permalink
Hotfix (#412)
Browse files Browse the repository at this point in the history
* Fix polling with large number of issues
  • Loading branch information
JunWei96 authored Apr 18, 2020
1 parent bd82f4f commit 497311c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 20 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "CATcher",
"version": "3.2.2",
"version": "3.2.3",
"main": "main.js",
"scripts": {
"postinstall": "npm run postinstall:electron && electron-builder install-app-deps",
Expand Down
35 changes: 23 additions & 12 deletions src/app/core/services/github.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,17 @@ export class GithubService {
/**
* Will return an Observable with array of all of the issues in Github including the paginated issues.
*/
fetchIssues(filter?: {}): Observable<Array<GithubIssue>> {
fetchIssues(filter?: {}, forceFetch: boolean = false): Observable<Array<GithubIssue>> {
let responseInFirstPage: GithubResponse<GithubIssue[]>;
return from(this.getIssueAPICall(filter, 1)).pipe(
return from(this.getIssueAPICall(filter, 1, forceFetch)).pipe(
map((response: GithubResponse<GithubIssue[]>) => {
responseInFirstPage = response;
return this.getNumberOfPages(response);
}),
flatMap((numOfPages: number) => {
const apiCalls: Observable<GithubResponse<GithubIssue[]>>[] = [];
for (let i = 2; i <= numOfPages; i++) {
apiCalls.push(from(this.getIssueAPICall(filter, i)));
apiCalls.push(from(this.getIssueAPICall(filter, i, forceFetch)));
}
return apiCalls.length === 0 ? of([]) : forkJoin(apiCalls);
}),
Expand All @@ -94,17 +94,18 @@ export class GithubService {
);
}

fetchIssueComments(issueId: number): Observable<Array<GithubComment>> {
fetchIssueComments(issueId: number, forceFetch: boolean = false): Observable<Array<GithubComment>> {
let responseInFirstPage: GithubResponse<GithubComment[]>;
return from(this.getCommentsAPICall(issueId, 1)).pipe(
return from(this.getCommentsAPICall(issueId, 1, forceFetch)).pipe(
map((response: GithubResponse<GithubComment[]>) => {
responseInFirstPage = response;
console.log('got number of pages in ', issueId);
return this.getNumberOfPages(response);
}),
flatMap((numOfPages: number) => {
const apiCalls: Observable<GithubResponse<GithubComment[]>>[] = [];
for (let i = 2; i <= numOfPages; i++) {
apiCalls.push(from(this.getCommentsAPICall(issueId, i)));
apiCalls.push(from(this.getCommentsAPICall(issueId, i, forceFetch)));
}
return apiCalls.length === 0 ? of([]) : forkJoin(apiCalls);
}),
Expand All @@ -119,6 +120,7 @@ export class GithubService {
collatedData.push(comment);
}
}
console.log('collated comments for issueId', issueId, ' ', collatedData);
return collatedData;
})
);
Expand Down Expand Up @@ -304,13 +306,22 @@ export class GithubService {
return numberOfPages;
}

private getIssueAPICall(filter: {}, pageNumber: number): Promise<GithubResponse<GithubIssue[]>> {
return octokit.issues.listForRepo({...filter, owner: ORG_NAME, repo: REPO, sort: 'created',
direction: 'desc', per_page: 100, page: pageNumber, headers: { 'If-None-Match': this.issuesEtagManager.get(pageNumber) }});
private getIssueAPICall(filter: {}, pageNumber: number, force: boolean = false): Promise<GithubResponse<GithubIssue[]>> {
if (force) {
return octokit.issues.listForRepo({...filter, owner: ORG_NAME, repo: REPO, sort: 'created',
direction: 'desc', per_page: 100, page: pageNumber});
} else {
return octokit.issues.listForRepo({...filter, owner: ORG_NAME, repo: REPO, sort: 'created',
direction: 'desc', per_page: 100, page: pageNumber, headers: { 'If-None-Match': this.issuesEtagManager.get(pageNumber) }});
}
}

private getCommentsAPICall(issueId: number, pageNumber: number): Promise<GithubResponse<GithubComment[]>> {
return octokit.issues.listComments({owner: ORG_NAME, repo: REPO, issue_number: issueId, page: pageNumber, per_page: 100,
headers: { 'If-None-Match': this.commentsEtagManager.get(issueId, pageNumber)}});
private getCommentsAPICall(issueId: number, pageNumber: number, force: boolean = false): Promise<GithubResponse<GithubComment[]>> {
if (force) {
return octokit.issues.listComments({owner: ORG_NAME, repo: REPO, issue_number: issueId, page: pageNumber, per_page: 100});
} else {
return octokit.issues.listComments({owner: ORG_NAME, repo: REPO, issue_number: issueId, page: pageNumber, per_page: 100,
headers: { 'If-None-Match': this.commentsEtagManager.get(issueId, pageNumber)}});
}
}
}
4 changes: 2 additions & 2 deletions src/app/core/services/issue-comment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export class IssueCommentService {

constructor(private githubService: GithubService) {}

getGithubComments(issueId: number): Observable<GithubComment[]> {
return this.githubService.fetchIssueComments(issueId).pipe(
getGithubComments(issueId: number, forceFetch: boolean = false): Observable<GithubComment[]> {
return this.githubService.fetchIssueComments(issueId, forceFetch).pipe(
map((githubComments: Array<GithubComment>) => {
this.updateLocalIssueComments(issueId, githubComments);
return githubComments.map(rawJsonData => <GithubComment>{...rawJsonData});
Expand Down
15 changes: 10 additions & 5 deletions src/app/core/services/issue.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export class IssueService {
private issueTeamFilter = 'All Teams';
readonly MINIMUM_MATCHES = 1;

private toForceFetch = true;

constructor(private githubService: GithubService,
private userService: UserService,
private phaseService: PhaseService,
Expand Down Expand Up @@ -266,10 +268,10 @@ export class IssueService {

const issuesPerFilter = [];
if (filters.length === 0) {
issuesPerFilter.push(this.githubService.fetchIssues({}));
issuesPerFilter.push(this.githubService.fetchIssues({}, this.toForceFetch));
}
for (const filter of filters) {
issuesPerFilter.push(this.githubService.fetchIssues(filter));
issuesPerFilter.push(this.githubService.fetchIssues(filter, this.toForceFetch));
}

return forkJoin(issuesPerFilter).pipe(
Expand All @@ -283,6 +285,9 @@ export class IssueService {
return mappingFunctions.length === 0 ? of([]) : forkJoin(mappingFunctions);
}),
map(() => {
if (this.toForceFetch) {
this.toForceFetch = false;
}
return Object.values(this.issues);
})
);
Expand Down Expand Up @@ -359,20 +364,20 @@ export class IssueService {
case Phase.phaseBugReporting:
return of(Issue.createPhaseBugReportingIssue(githubIssue));
case Phase.phaseTeamResponse:
return this.issueCommentService.getGithubComments(githubIssue.number).pipe(
return this.issueCommentService.getGithubComments(githubIssue.number, this.toForceFetch).pipe(
map((githubComments: GithubComment[]) => {
return Issue.createPhaseTeamResponseIssue(githubIssue, githubComments,
this.dataService.getTeam(this.extractTeamIdFromGithubIssue(githubIssue)));
})
);
case Phase.phaseTesterResponse:
return this.issueCommentService.getGithubComments(githubIssue.number).pipe(
return this.issueCommentService.getGithubComments(githubIssue.number, this.toForceFetch).pipe(
map((githubComments: GithubComment[]) => {
return Issue.createPhaseTesterResponseIssue(githubIssue, githubComments);
})
);
case Phase.phaseModeration:
return this.issueCommentService.getGithubComments(githubIssue.number).pipe(
return this.issueCommentService.getGithubComments(githubIssue.number, this.toForceFetch).pipe(
map((githubComments: GithubComment[]) => {
return Issue.createPhaseModerationIssue(githubIssue, githubComments,
this.dataService.getTeam(this.extractTeamIdFromGithubIssue(githubIssue)));
Expand Down

0 comments on commit 497311c

Please sign in to comment.