Skip to content

Commit eb010b4

Browse files
committed
Fixed manual analysis now overriding throttling
1 parent 4591a09 commit eb010b4

3 files changed

Lines changed: 39 additions & 30 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@
167167
},
168168
{
169169
"view": "deepcode.views.actions",
170-
"contents": "You are currently running DeepCode in throttled mode. It scans your code every 30 minutes if it detects changes in your files.\n[Auto](command:deepcode.setmode?%5B%22auto%22%5D)",
170+
"contents": "You are currently running DeepCode in throttled mode. It scans your code every 30 minutes if it detects changes in your files.\n[Analyze now](command:deepcode.start)\n[Switch to auto-scan mode](command:deepcode.setmode?%5B%22auto%22%5D)",
171171
"when": "deepcode:mode == 'throttled'"
172172
},
173173
{

src/deepcode/constants/general.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ export const ALLOWED_PAYLOAD_SIZE = 1024 * 1024 * 4; // max payload size of 4MB
55
export const MAX_CONNECTION_RETRIES = 5; // max number of automatic retries before showing an error
66
export const IDE_NAME = "vscode";
77
export const EXECUTION_DEBOUNCE_INTERVAL = 1000; // 1 second
8-
export const EXECUTION_DEBOUNCE_EXTENDED_INTERVAL = 1000 * 60 * 30; // 30 minutes
8+
export const EXECUTION_DEBOUNCE_EXTENDED_INTERVAL = 1000 * 10;// * 60 * 30; // 30 minutes
99
export const EXECUTION_PAUSE_INTERVAL = 1000 * 60 * 30; // 30 minutes
1010
export const REFRESH_VIEW_DEBOUNCE_INTERVAL = 200; // 200 milliseconds

src/deepcode/lib/modules/DeepCodeLib.ts

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,22 @@ export default class DeepCodeLib extends BundlesModule implements DeepCode.DeepC
1313
private _mode = DEEPCODE_MODE_CODES.AUTO;
1414
// Platform-independant type definition.
1515
private _unpauseTimeout: ReturnType<typeof setTimeout> | undefined;
16+
private _lastExecution: number | undefined;
1617

17-
private unpause() {
18+
private shouldBeThrottled(): boolean {
19+
if (this._mode !== DEEPCODE_MODE_CODES.THROTTLED) return false;
20+
const now = Date.now();
21+
if (
22+
this._lastExecution === undefined ||
23+
(now - this._lastExecution) >= EXECUTION_DEBOUNCE_EXTENDED_INTERVAL
24+
) {
25+
this._lastExecution = now;
26+
return false;
27+
}
28+
return true;
29+
}
30+
31+
private unpause(): void {
1832
if (this._mode === DEEPCODE_MODE_CODES.PAUSED) this.setMode(DEEPCODE_MODE_CODES.AUTO);
1933
}
2034

@@ -39,28 +53,28 @@ export default class DeepCodeLib extends BundlesModule implements DeepCode.DeepC
3953
this.resetTransientErrors();
4054
}
4155

42-
private getDebouncedExecution(wait: number) {
43-
return _.debounce(
44-
async (manual = false): Promise<void> => {
45-
// If the execution is suspended, we only allow user-triggered analyses.
46-
if (!manual && [
47-
DEEPCODE_MODE_CODES.MANUAL,
48-
DEEPCODE_MODE_CODES.PAUSED
49-
].includes(this._mode)) return;
50-
// This function is called by commands, error handlers, etc.
51-
// We should avoid having duplicate parallel executions.
52-
try {
53-
await this.executeExtensionPipeline();
54-
} catch (err) {
55-
this.processError(err);
56-
}
57-
},
58-
wait,
59-
{ 'leading': true }
60-
);
61-
}
62-
63-
startExtension = this.getDebouncedExecution(EXECUTION_DEBOUNCE_INTERVAL);
56+
// This function is called by commands, error handlers, etc.
57+
// We should avoid having duplicate parallel executions.
58+
startExtension = _.debounce(
59+
async (manual = false): Promise<void> => {
60+
// If the execution is suspended, we only allow user-triggered analyses.
61+
if (!manual) {
62+
if ([
63+
DEEPCODE_MODE_CODES.MANUAL,
64+
DEEPCODE_MODE_CODES.PAUSED
65+
].includes(this._mode) ||
66+
this.shouldBeThrottled()
67+
) return;
68+
}
69+
try {
70+
await this.executeExtensionPipeline();
71+
} catch (err) {
72+
this.processError(err);
73+
}
74+
},
75+
EXECUTION_DEBOUNCE_INTERVAL,
76+
{ 'leading': true }
77+
);
6478

6579
setMode(mode: string): void {
6680
if (!Object.values(DEEPCODE_MODE_CODES).includes(mode)) return;
@@ -69,16 +83,11 @@ export default class DeepCodeLib extends BundlesModule implements DeepCode.DeepC
6983
switch(mode) {
7084
case DEEPCODE_MODE_CODES.PAUSED:
7185
this._unpauseTimeout = setTimeout(this.unpause.bind(this), EXECUTION_PAUSE_INTERVAL);
72-
this.startExtension = this.getDebouncedExecution(EXECUTION_DEBOUNCE_INTERVAL);
7386
break;
7487
case DEEPCODE_MODE_CODES.AUTO:
7588
case DEEPCODE_MODE_CODES.MANUAL:
76-
if (this._unpauseTimeout) clearTimeout(this._unpauseTimeout);
77-
this.startExtension = this.getDebouncedExecution(EXECUTION_DEBOUNCE_INTERVAL);
78-
break;
7989
case DEEPCODE_MODE_CODES.THROTTLED:
8090
if (this._unpauseTimeout) clearTimeout(this._unpauseTimeout);
81-
this.startExtension = this.getDebouncedExecution(EXECUTION_DEBOUNCE_EXTENDED_INTERVAL);
8291
break;
8392
}
8493
}

0 commit comments

Comments
 (0)