Skip to content

Commit 06b929e

Browse files
authored
Merge pull request #62 from edgardmessias/branch_list
Reduced calls to branch listings
2 parents 630cf77 + a3c1f8c commit 06b929e

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
* @edgardmessias Fixed config option form svn path
3030
* @JohnstonCode Fixed conflicted files not having an icon
31+
* @edgardmessias Reduced calls to branch listings
3132

3233
# **v1.3.2**
3334

src/repository.ts

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ import { Resource } from "./resource";
1414
import { throttle, debounce } from "./decorators";
1515
import { Repository as BaseRepository } from "./svnRepository";
1616
import { SvnStatusBar } from "./statusBar";
17-
import { dispose, anyEvent, filterEvent } from "./util";
17+
import { dispose, anyEvent, filterEvent, toDisposable } from "./util";
1818
import * as path from "path";
19+
import { setInterval, clearInterval } from "timers";
1920

2021
export class Repository {
2122
public watcher: FileSystemWatcher;
@@ -26,6 +27,7 @@ export class Repository {
2627
public currentBranch = "";
2728
public isSwitchingBranch: boolean = false;
2829
public branches: any[] = [];
30+
public branchesTimer: NodeJS.Timer;
2931

3032
private _onDidChangeRepository = new EventEmitter<Uri>();
3133
readonly onDidChangeRepository: Event<Uri> = this._onDidChangeRepository
@@ -94,6 +96,11 @@ export class Repository {
9496
null,
9597
this.disposables
9698
);
99+
this.onDidChangeRepository(
100+
() => (this.sourceControl.statusBarCommands = statusBar.commands),
101+
null,
102+
this.disposables
103+
);
97104
this.sourceControl.statusBarCommands = statusBar.commands;
98105

99106
this.changes = this.sourceControl.createResourceGroup("changes", "Changes");
@@ -105,9 +112,22 @@ export class Repository {
105112
this.changes.hideWhenEmpty = true;
106113
this.notTracked.hideWhenEmpty = true;
107114

115+
this.disposables.push(toDisposable(() => clearInterval(this.branchesTimer)));
116+
setInterval(() => {this.updateBranches()}, 1000 * 60 * 5); // 5 minutes
117+
118+
this.updateBranches();
108119
this.update();
109120
}
110121

122+
@debounce(1000)
123+
async updateBranches() {
124+
try {
125+
this.branches = await this.repository.getBranches();
126+
} catch (error) {
127+
console.error(error);
128+
}
129+
}
130+
111131
@debounce(1000)
112132
async update() {
113133
let changes: any[] = [];
@@ -147,12 +167,6 @@ export class Repository {
147167

148168
this.currentBranch = await this.getCurrentBranch();
149169

150-
try {
151-
this.branches = await this.repository.getBranches();
152-
} catch (error) {
153-
console.error(error);
154-
}
155-
156170
this._onDidChangeStatus.fire();
157171

158172
return Promise.resolve();
@@ -182,16 +196,23 @@ export class Repository {
182196
return this.repository.getCurrentBranch();
183197
}
184198

185-
branch(name: string) {
186-
return this.repository.branch(name);
199+
async branch(name: string) {
200+
this.isSwitchingBranch = true;
201+
this._onDidChangeRepository.fire();
202+
const response = await this.repository.branch(name);
203+
this.isSwitchingBranch = false;
204+
this.updateBranches();
205+
this._onDidChangeRepository.fire();
206+
return response;
187207
}
188208

189209
async switchBranch(name: string) {
190210
this.isSwitchingBranch = true;
191-
this._onDidChangeStatus.fire();
211+
this._onDidChangeRepository.fire();
192212
const response = await this.repository.switchBranch(name);
193213
this.isSwitchingBranch = false;
194-
this._onDidChangeStatus.fire();
214+
this.updateBranches();
215+
this._onDidChangeRepository.fire();
195216
return response;
196217
}
197218
}

0 commit comments

Comments
 (0)