Skip to content

Commit 17ad74e

Browse files
committed
fix #282 Don't clear cached mtime too soon during import
1 parent abfd788 commit 17ad74e

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/commands/compile.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@ async function compileFlags(): Promise<string> {
2828
});
2929
}
3030

31+
/**
32+
* For files being locally edited, get and return its mtime timestamp from workspace-state cache if present there,
33+
* else get from server. May update cache.
34+
* - If mtime fetched from server is later than local file mtime, or if `force` parameter is `true`, cache server mtime and return it.
35+
* - Otherwise if server fetch fails, clear cache entry and return -1.
36+
* - Otherwise cache local file mtime and return it.
37+
*
38+
* For other file types (e.g. isfs) return -1 and do not alter cache.
39+
* @param file File to check.
40+
* @param force If passed true, use server mtime.
41+
* @return mtime timestamp or -1.
42+
*/
3143
export async function checkChangedOnServer(file: CurrentFile, force = false): Promise<number> {
3244
if (!file || !file.uri || schemas.includes(file.uri.scheme)) {
3345
return -1;
@@ -57,7 +69,6 @@ async function importFile(file: CurrentFile, ignoreConflict?: boolean): Promise<
5769
const api = new AtelierAPI(file.uri);
5870
const content = file.content.split(/\r?\n/);
5971
const mtime = await checkChangedOnServer(file);
60-
workspaceState.update(`${file.uniqueId}:mtime`, undefined);
6172
ignoreConflict = ignoreConflict || mtime < 0;
6273
return api
6374
.putDoc(
@@ -70,6 +81,9 @@ async function importFile(file: CurrentFile, ignoreConflict?: boolean): Promise<
7081
ignoreConflict
7182
)
7283
.then(() => {
84+
// Clear cache entry
85+
workspaceState.update(`${file.uniqueId}:mtime`, undefined);
86+
// Create fresh cache entry
7387
checkChangedOnServer(file, true);
7488
})
7589
.catch((error) => {
@@ -103,6 +117,9 @@ What do you want to do?`,
103117
)
104118
.then(() => Promise.reject());
105119
case "Overwrite on Server":
120+
// Clear cache entry
121+
workspaceState.update(`${file.uniqueId}:mtime`, undefined);
122+
// Overwrite
106123
return importFile(file, true);
107124
case "Pull Server Changes":
108125
outputChannel.appendLine(`${file.name}: Loading changes from server`);

0 commit comments

Comments
 (0)