Skip to content

Commit 118f2de

Browse files
committed
fix: Fixed high cpu usage by parallel svn processes (close JohnstonCode#463)
1 parent 23f0a06 commit 118f2de

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/decorators.ts

+14
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,17 @@ export function debounce(delay: number): Function {
104104
};
105105
});
106106
}
107+
108+
const _seqList: { [key: string]: any } = {};
109+
110+
export function globalSequentialize(name: string): Function {
111+
return decorate((fn, key) => {
112+
return function(...args: any[]) {
113+
const currentPromise =
114+
(_seqList[name] as Promise<any>) || Promise.resolve(null);
115+
const run = async () => fn.apply(this, args);
116+
_seqList[name] = currentPromise.then(run, run);
117+
return _seqList[name];
118+
};
119+
});
120+
}

src/repository.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
Status,
2626
SvnUriAction
2727
} from "./common/types";
28-
import { debounce, memoize, throttle } from "./decorators";
28+
import { debounce, globalSequentialize, memoize, throttle } from "./decorators";
2929
import { configuration } from "./helpers/configuration";
3030
import OperationsImpl from "./operationsImpl";
3131
import { PathNormalizer } from "./pathNormalizer";
@@ -427,6 +427,7 @@ export class Repository implements IRemoteRepository {
427427
}
428428

429429
@throttle
430+
@globalSequentialize("updateModelState")
430431
public async updateModelState(checkRemoteChanges: boolean = false) {
431432
const changes: any[] = [];
432433
const unversioned: any[] = [];

0 commit comments

Comments
 (0)