Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 30 additions & 19 deletions src/view/prsTreeModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class PrsTreeModel extends Disposable {

private _cachedPRs: Map<FolderRepositoryManager, Map<string | PRType.LocalPullRequest | PRType.All, ItemsResponseResult<PullRequestModel>>> = new Map();
private readonly _repoEvents: Map<FolderRepositoryManager, vscode.Disposable[]> = new Map();
private _getPullRequestsForQueryLock: Promise<void> = Promise.resolve();

constructor(private _telemetry: ITelemetry, private readonly _reposManager: RepositoriesManager, private readonly _context: vscode.ExtensionContext) {
super();
Expand Down Expand Up @@ -238,26 +239,36 @@ export class PrsTreeModel extends Disposable {
}

async getPullRequestsForQuery(folderRepoManager: FolderRepositoryManager, fetchNextPage: boolean, query: string): Promise<ItemsResponseResult<PullRequestModel>> {
const cache = this.getFolderCache(folderRepoManager);
if (!fetchNextPage && cache.has(query)) {
return cache.get(query)!;
}

const prs = await folderRepoManager.getPullRequests(
PRType.Query,
{ fetchNextPage },
query,
);
cache.set(query, prs);
let release: () => void;
const lock = new Promise<void>(resolve => { release = resolve; });
const prev = this._getPullRequestsForQueryLock;
this._getPullRequestsForQueryLock = prev.then(() => lock);
await prev;

try {
const cache = this.getFolderCache(folderRepoManager);
if (!fetchNextPage && cache.has(query)) {
return cache.get(query)!;
}

/* __GDPR__
"pr.expand.query" : {}
*/
this._telemetry.sendTelemetryEvent('pr.expand.query');
// Don't await this._getChecks. It fires an event that will be listened to.
this._getChecks(prs.items);
this.hasLoaded = true;
return prs;
const prs = await folderRepoManager.getPullRequests(
PRType.Query,
{ fetchNextPage },
query,
);
cache.set(query, prs);

/* __GDPR__
"pr.expand.query" : {}
*/
this._telemetry.sendTelemetryEvent('pr.expand.query');
// Don't await this._getChecks. It fires an event that will be listened to.
this._getChecks(prs.items);
this.hasLoaded = true;
return prs;
} finally {
release!();
}
}

async getAllPullRequests(folderRepoManager: FolderRepositoryManager, fetchNextPage: boolean, update?: boolean): Promise<ItemsResponseResult<PullRequestModel>> {
Expand Down
5 changes: 0 additions & 5 deletions src/view/treeNodes/pullRequestNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ export class PRNode extends TreeNode implements vscode.CommentingRangeProvider2
super(parent);
this.registerSinceReviewChange();
this.registerConfigurationChange();
this._register(this.pullRequestModel.onDidChange((e) => {
if (e.title || e.state) {
this.refresh(this);
}
}));
this._register(this._folderReposManager.onDidChangeActivePullRequest(e => {
if (e.new?.number === this.pullRequestModel.number || e.old?.number === this.pullRequestModel.number) {
this.refresh(this);
Expand Down