Skip to content

Commit aa30045

Browse files
committed
Make mark PRs as done less expensive
1 parent 7886871 commit aa30045

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
@@ -904,6 +904,31 @@ export class PullRequestModel extends IssueModel<PullRequest> implements IPullRe
904904
return events;
905905
}
906906

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