Skip to content

Commit 3ff34df

Browse files
committed
Move MINIMUM_WAIT_TIME to shared constants and enforce it in install specific version command
- getting list of old versions should take at least 2 seconds, just like checking for updates - move wait time to `apps/editor/src/constants/values.ts` └── apps └── editor └── src ├── commands │ ├── check-for-updates-command.ts │ ├── index.ts │ └── install-specific-version-command.ts ├── constants │ └── values.ts ├── extension.ts ├── i18n │ └── translations │ └── commands │ └── install-specific-version-command.ts └── views └── prompt └── backend └── utils └── check-for-updates.ts
1 parent 9357e13 commit 3ff34df

3 files changed

Lines changed: 12 additions & 2 deletions

File tree

‎apps/editor/src/commands/check-for-updates-command.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import * as vscode from 'vscode'
22
import { t } from '../i18n'
33
import { PromptViewProvider } from '../views/prompt/backend/prompt-view-provider'
44
import { update_extension } from '../utils/update-extension'
5-
6-
const MINIMUM_WAIT_TIME = 2000
5+
import { MINIMUM_WAIT_TIME } from '../constants/values'
76

87
export const check_for_updates_command = (
98
prompt_view_provider: PromptViewProvider

‎apps/editor/src/commands/install-specific-version-command.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as vscode from 'vscode'
22
import axios from 'axios'
33
import { t } from '../i18n'
44
import { update_extension } from '../utils/update-extension'
5+
import { MINIMUM_WAIT_TIME } from '../constants/values'
56

67
export const install_specific_version_command = () => {
78
return vscode.commands.registerCommand(
@@ -19,6 +20,8 @@ export const install_specific_version_command = () => {
1920
cancellable: false
2021
},
2122
async () => {
23+
const start_time = Date.now()
24+
2225
while (true) {
2326
try {
2427
const res = await axios.get(
@@ -47,6 +50,13 @@ export const install_specific_version_command = () => {
4750
break
4851
}
4952
}
53+
54+
const elapsed_time = Date.now() - start_time
55+
if (elapsed_time < MINIMUM_WAIT_TIME) {
56+
await new Promise((resolve) =>
57+
setTimeout(resolve, MINIMUM_WAIT_TIME - elapsed_time)
58+
)
59+
}
5060
}
5161
)
5262

‎apps/editor/src/constants/values.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export const MAX_PROMPT_CHARS_IN_COMMIT_MESSAGE = 1000
44
export const GIT_LOG_SINCE_DURATION = '6 months ago'
55
export const SYMBOL_CACHE_DURATION = 5 * 60 * 1000
66
export const UPDATE_CHECK_INTERVAL = 5 * 60 * 1000 // 5 minutes
7+
export const MINIMUM_WAIT_TIME = 2000
78

89
export const DIFF_PLACEHOLDERS = {
910
FILE_CREATED: 'File created',

0 commit comments

Comments
 (0)