Skip to content

Commit 54ac859

Browse files
authored
Cache copilot timeline events (#7973)
1 parent cadf693 commit 54ac859

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/github/copilotPrWatcher.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ export class CopilotPRWatcher extends Disposable {
270270
private async _updateSingleState(pr: PullRequestModel): Promise<void> {
271271
const changes: { pullRequestModel: PullRequestModel, status: CopilotPRStatus }[] = [];
272272

273-
const copilotEvents = await pr.getCopilotTimelineEvents(pr);
273+
const copilotEvents = await pr.getCopilotTimelineEvents(pr, false, !this._model.isInitialized);
274274
let latestEvent = copilotEventToStatus(copilotEvents[copilotEvents.length - 1]);
275275
if (latestEvent === CopilotPRStatus.None) {
276276
if (!COPILOT_ACCOUNTS[pr.author.login]) {
@@ -315,7 +315,7 @@ export class CopilotPRWatcher extends Disposable {
315315

316316
for (const pr of items) {
317317
unseenKeys.delete(this._model.makeKey(pr.remote.owner, pr.remote.repositoryName, pr.number));
318-
const copilotEvents = await pr.getCopilotTimelineEvents(pr);
318+
const copilotEvents = await pr.getCopilotTimelineEvents(pr, false, !this._model.isInitialized);
319319
let latestEvent = copilotEventToStatus(copilotEvents[copilotEvents.length - 1]);
320320
if (latestEvent === CopilotPRStatus.None) {
321321
if (!COPILOT_ACCOUNTS[pr.author.login]) {

src/github/issueModel.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export class IssueModel<TItem extends Issue = Issue> extends Disposable {
6868
private _lastCheckedForUpdatesAt?: Date;
6969

7070
private _timelineEvents: readonly TimelineEvent[] | undefined;
71+
private _copilotTimelineEvents: TimelineEvent[] | undefined;
7172

7273
protected _onDidChange = this._register(new vscode.EventEmitter<IssueChangeEvent>());
7374
public onDidChange = this._onDidChange.event;
@@ -514,13 +515,19 @@ export class IssueModel<TItem extends Issue = Issue> extends Disposable {
514515
/**
515516
* TODO: @alexr00 we should delete this https://github.com/microsoft/vscode-pull-request-github/issues/6965
516517
*/
517-
async getCopilotTimelineEvents(issueModel: IssueModel, skipMerge: boolean = false): Promise<TimelineEvent[]> {
518+
async getCopilotTimelineEvents(issueModel: IssueModel, skipMerge: boolean = false, useCache: boolean = false): Promise<TimelineEvent[]> {
518519
if (!COPILOT_ACCOUNTS[issueModel.author.login]) {
519520
return [];
520521
}
521522

522523
Logger.debug(`Fetch Copilot timeline events of issue #${issueModel.number} - enter`, GitHubRepository.ID);
523524

525+
if (useCache && this._copilotTimelineEvents) {
526+
Logger.debug(`Fetch Copilot timeline events of issue #${issueModel.number} (used cache) - exit`, GitHubRepository.ID);
527+
528+
return this._copilotTimelineEvents;
529+
}
530+
524531
const { octokit, remote } = await this.githubRepository.ensure();
525532
try {
526533
const timeline = await restPaginate<typeof octokit.api.issues.listEventsForTimeline, OctokitCommon.ListEventsForTimelineResponse>(octokit.api.issues.listEventsForTimeline, {
@@ -531,6 +538,7 @@ export class IssueModel<TItem extends Issue = Issue> extends Disposable {
531538
});
532539

533540
const timelineEvents = parseSelectRestTimelineEvents(issueModel, timeline);
541+
this._copilotTimelineEvents = timelineEvents;
534542
if (timelineEvents.length === 0) {
535543
return [];
536544
}

0 commit comments

Comments
 (0)