Skip to content

Commit d3b9fd3

Browse files
authored
Make mark PRs as done less expensive (#8318)
1 parent 3632c53 commit d3b9fd3

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

src/github/pullRequestModel.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,31 @@ export class PullRequestModel extends IssueModel<PullRequest> implements IPullRe
906906
return events;
907907
}
908908

909+
async getActivityTimelineEvents(): Promise<TimelineEvent[]> {
910+
Logger.debug(`Fetch timeline events of PR #${this.number} - enter`, PullRequestModel.ID);
911+
const { query, remote, schema } = await this.githubRepository.ensure();
912+
try {
913+
const { data } = await query<TimelineEventsResponse>({
914+
query: schema.PullRequestActivityTimelineEvents,
915+
variables: {
916+
owner: remote.owner,
917+
name: remote.repositoryName,
918+
number: this.number,
919+
},
920+
});
921+
922+
if (data.repository === null) {
923+
Logger.error('Unexpected null repository when fetching timeline', PullRequestModel.ID);
924+
}
925+
926+
return parseCombinedTimelineEvents(data.repository?.pullRequest.timelineItems.nodes ?? [], [], this.githubRepository);
927+
} catch (e) {
928+
Logger.error(`Failed to get pull request timeline events: ${e}`, PullRequestModel.ID);
929+
console.log(e);
930+
return [];
931+
}
932+
}
933+
909934
private addReviewTimelineEventComments(events: TimelineEvent[], reviewThreads: IReviewThread[]): void {
910935
interface CommentNode extends IComment {
911936
childComments?: CommentNode[];

src/github/queriesShared.gql

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,26 @@ query TimelineEvents($owner: String!, $name: String!, $number: Int!, $last: Int
321321
}
322322
}
323323

324+
query PullRequestActivityTimelineEvents($owner: String!, $name: String!, $number: Int!, $last: Int = 5) {
325+
repository(owner: $owner, name: $name) {
326+
pullRequest(number: $number) {
327+
timelineItems(last: $last) {
328+
nodes {
329+
__typename
330+
...Merged
331+
...Comment
332+
...Review
333+
...Commit
334+
...ClosedEvent
335+
}
336+
}
337+
}
338+
}
339+
rateLimit {
340+
...RateLimit
341+
}
342+
}
343+
324344
query IssueTimelineEvents($owner: String!, $name: String!, $number: Int!, $last: Int = 150) {
325345
repository(owner: $owner, name: $name) {
326346
pullRequest: issue(number: $number) {

src/notifications/notificationsManager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,15 +371,15 @@ export class NotificationsManager extends Disposable implements vscode.TreeDataP
371371

372372
public async markPullRequests(markAsDone: boolean = false): Promise<void> {
373373
const filteredNotifications = Array.from(this._notifications.values()).filter(notification => notification.notification.subject.type === NotificationSubjectType.PullRequest);
374-
const timlines = await Promise.all(filteredNotifications.map(notification => (notification.model as PullRequestModel).getTimelineEvents()));
374+
const timelines = await Promise.all(filteredNotifications.map(notification => (notification.model as PullRequestModel).getActivityTimelineEvents()));
375375

376376
const markPromises: Promise<void>[] = [];
377377

378378
for (const [index, notification] of filteredNotifications.entries()) {
379379
const currentUser = await this._credentialStore.getCurrentUser(notification.model.remote.authProviderId);
380380

381381
// Check that there have been no comments, reviews, or commits, since last read
382-
const timeline = timlines[index];
382+
const timeline = timelines[index];
383383
let userLastEvent: Date | undefined = undefined;
384384
let nonUserLastEvent: Date | undefined = undefined;
385385
for (let i = timeline.length - 1; i >= 0; i--) {

0 commit comments

Comments
 (0)