Skip to content

Commit d7d5afd

Browse files
authored
Fix extra search API calls when polling for Padawan PR changes (#7544)
* Fix extra search API calls when polling for Padawan PR changes Part of #7542 * Fix the debounce
1 parent 6fba925 commit d7d5afd

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/github/copilotPrWatcher.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as vscode from 'vscode';
7+
import { debounce } from '../common/async';
78
import { COPILOT_ACCOUNTS } from '../common/comment';
89
import { COPILOT_LOGINS, copilotEventToStatus, CopilotPRStatus } from '../common/copilot';
910
import { Disposable } from '../common/lifecycle';
@@ -61,11 +62,11 @@ export class CopilotStateModel extends Disposable {
6162
changedModels.push(pullRequestModel);
6263
changedKeys.push(key);
6364
}
64-
if (this._isInitialized) {
65-
changedKeys.forEach(key => this._showNotification.add(key));
66-
this._onDidChangeNotifications.fire(changedModels);
67-
}
6865
if (changedModels.length > 0) {
66+
if (this._isInitialized) {
67+
changedKeys.forEach(key => this._showNotification.add(key));
68+
this._onDidChangeNotifications.fire(changedModels);
69+
}
6970
this._onDidChangeStates.fire();
7071
}
7172
}
@@ -139,7 +140,12 @@ export class CopilotPRWatcher extends Disposable {
139140
private _initialize() {
140141
this._getStateChanges();
141142
this._pollForChanges();
142-
this._register(this._reposManager.onDidChangeAnyPullRequests(() => this._getStateChanges()));
143+
const updateState = debounce(() => this._getStateChanges(), 50);
144+
this._register(this._reposManager.onDidChangeAnyPullRequests(e => {
145+
if (e.some(pr => COPILOT_ACCOUNTS[pr.model.author.login])) {
146+
updateState();
147+
}
148+
}));
143149
this._register(PullRequestOverviewPanel.onVisible(e => this._model.clearNotification(e.remote.owner, e.remote.repositoryName, e.number)));
144150

145151
this._register(vscode.workspace.onDidChangeConfiguration(e => {

0 commit comments

Comments
 (0)