Skip to content

Commit 4b9a526

Browse files
committed
shorten unignore duration
1 parent 765ba51 commit 4b9a526

File tree

4 files changed

+22
-21
lines changed

4 files changed

+22
-21
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ dist
1313
*.zip
1414
*.tar.gz
1515
*.log
16-
*.js
16+
*.js
17+
18+
client/tests/test-client*

client/src/fileWatcher.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,24 @@ export enum FileOperationType {
99
Sync,
1010
}
1111

12-
let watcher: FSWatcher | undefined;
12+
export const UNIGNORE_DURATION = 200; // short because it only has to cover: end of operation -> file watcher trigger -> ignore that call
1313
export const WATCHER_DEBOUNCE_DURATION = 500;
1414
export const IGNORE_CLEANUP_DURATION = WATCHER_DEBOUNCE_DURATION * 2;
15+
16+
let watcher: FSWatcher | undefined;
1517
const ignoreMaps = {
1618
[FileOperationType.Remove]: new Map<string, number>(),
1719
[FileOperationType.Sync]: new Map<string, number>(),
1820
};
1921

20-
export function ignoreNext(fileOperationType: FileOperationType, path: string) {
22+
export function ignore(fileOperationType: FileOperationType, path: string) {
2123
ignoreMaps[fileOperationType].set(path, Date.now());
2224
}
2325

24-
export function unignoreNext(
25-
fileOperationType: FileOperationType,
26-
path: string,
27-
) {
26+
export function unignore(fileOperationType: FileOperationType, path: string) {
2827
setTimeout(() => {
2928
ignoreMaps[fileOperationType].delete(path);
30-
}, IGNORE_CLEANUP_DURATION);
29+
}, UNIGNORE_DURATION);
3130
}
3231

3332
function shouldIgnore(fileOperationType: FileOperationType, path: string) {

client/src/index.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ import {
1616
import {
1717
cleanupFileWatcher,
1818
FileOperationType,
19-
ignoreNext,
19+
ignore,
2020
setUpFileWatcher,
21-
unignoreNext,
21+
unignore,
2222
} from "./fileWatcher.js";
2323
import { cleanupWebsocket, setUpWebsocket } from "./setUpWebsocket.js";
2424
import { trackFileOperation } from "./trackFileOperation.js";
@@ -55,14 +55,14 @@ async function main() {
5555
try {
5656
changeTrayIconState(TrayIconState.Busy);
5757

58-
ignoreNext(FileOperationType.Sync, localPath);
58+
ignore(FileOperationType.Sync, localPath);
5959
await download(key, localPath);
6060
const { size } = await stat(localPath);
6161
trackFileOperation(key, size);
6262
} catch (error) {
6363
logger.error(`Error downloading file ${key}: ${getErrorMessage(error)}`);
6464
} finally {
65-
unignoreNext(FileOperationType.Sync, localPath);
65+
unignore(FileOperationType.Sync, localPath);
6666
changeTrayIconState(TrayIconState.Idle);
6767
}
6868
}
@@ -76,7 +76,7 @@ async function main() {
7676

7777
try {
7878
changeTrayIconState(TrayIconState.Busy);
79-
ignoreNext(FileOperationType.Remove, localPath);
79+
ignore(FileOperationType.Remove, localPath);
8080

8181
if ((await stat(localPath)).isDirectory()) {
8282
await rm(localPath, { recursive: true, force: true });
@@ -96,7 +96,7 @@ async function main() {
9696
);
9797
}
9898
} finally {
99-
unignoreNext(FileOperationType.Remove, localPath);
99+
unignore(FileOperationType.Remove, localPath);
100100
changeTrayIconState(TrayIconState.Idle);
101101
}
102102
}

client/src/s3Operations.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
S3_BUCKET,
2020
SECRET_KEY,
2121
} from "./consts.js";
22-
import { FileOperationType, ignoreNext, unignoreNext } from "./fileWatcher.js";
22+
import { FileOperationType, ignore, unignore } from "./fileWatcher.js";
2323

2424
export const s3Client = new S3Client({
2525
region: AWS_REGION,
@@ -32,9 +32,9 @@ export const s3Client = new S3Client({
3232
async function syncLastModified(localPath: string, lastModified?: Date) {
3333
if (lastModified) {
3434
logger.debug(`syncLastModified: added ${localPath} to ignore files.`);
35-
ignoreNext(FileOperationType.Sync, localPath);
35+
ignore(FileOperationType.Sync, localPath);
3636
await utimes(localPath, lastModified, lastModified);
37-
unignoreNext(FileOperationType.Sync, localPath);
37+
unignore(FileOperationType.Sync, localPath);
3838
}
3939
}
4040

@@ -86,12 +86,12 @@ export async function download(key: string, localPath: string) {
8686
}),
8787
);
8888

89-
ignoreNext(FileOperationType.Sync, localPath);
89+
ignore(FileOperationType.Sync, localPath);
9090
try {
9191
await mkdir(localPath, { recursive: true });
9292
await syncLastModified(localPath, LastModified);
9393
} finally {
94-
unignoreNext(FileOperationType.Sync, localPath);
94+
unignore(FileOperationType.Sync, localPath);
9595
}
9696

9797
logger.info(`Downloaded: ${key}`);
@@ -109,13 +109,13 @@ export async function download(key: string, localPath: string) {
109109
// We don't manage ignoring potentially new created directories here because that would be a lot of overhead. Instead, if syncing is triggered, we let the upload of the directory handle breaking that chain. (via updating modification time and that timestamp then being the same)
110110
await mkdir(dirname(localPath), { recursive: true });
111111

112-
ignoreNext(FileOperationType.Sync, localPath);
112+
ignore(FileOperationType.Sync, localPath);
113113
try {
114114
const writeStream = createWriteStream(localPath);
115115
await pipeline(Body.transformToWebStream(), writeStream);
116116
await syncLastModified(localPath, LastModified);
117117
} finally {
118-
unignoreNext(FileOperationType.Sync, localPath);
118+
unignore(FileOperationType.Sync, localPath);
119119
}
120120

121121
logger.info(`Downloaded: ${key}`);

0 commit comments

Comments
 (0)