Skip to content

Commit 9d32c83

Browse files
committed
fix bug in recording file save time, which indirectly broke latex
1 parent f52add1 commit 9d32c83

File tree

3 files changed

+30
-45
lines changed

3 files changed

+30
-45
lines changed

src/packages/frontend/frame-editors/latex-editor/actions.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,8 @@ export class Actions extends BaseActions<LatexEditorState> {
676676
await this.build(); // kicks off a save of all relevant files
677677
}
678678

679-
// used by generic framework – this is bound to the instance, otherwise "this" is undefined
679+
// used by generic framework – this is bound to the instance, otherwise "this" is undefined, hence
680+
// make sure to use an arrow function!
680681
build = async (id?: string, force: boolean = false): Promise<void> => {
681682
this.set_error("");
682683
this.set_status("");
@@ -699,6 +700,7 @@ export class Actions extends BaseActions<LatexEditorState> {
699700
await this.save_all(false);
700701
await this.run_build(this.last_save_time(), force);
701702
} catch (err) {
703+
this.set_error(`${err}`);
702704
// if there is an error, we issue a stop, but keep the build logs
703705
await this.stop_build();
704706
} finally {

src/packages/sync/editor/generic/sync-doc.ts

Lines changed: 26 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -987,15 +987,11 @@ export class SyncDoc extends EventEmitter {
987987
this.assert_table_is_ready("syncstring");
988988
this.dbg("set_initialized")({ error, read_only, size });
989989
const init = { time: this.client.server_time(), size, error };
990-
this.syncstring_table.set({
991-
string_id: this.string_id,
992-
project_id: this.project_id,
993-
path: this.path,
990+
await this.set_syncstring_table({
994991
init,
995992
read_only,
996993
last_active: this.client.server_time(),
997994
});
998-
await this.syncstring_table.save();
999995
}
1000996

1001997
/* List of timestamps of the versions of this string in the sync
@@ -1287,13 +1283,9 @@ export class SyncDoc extends EventEmitter {
12871283
dbg("getting table...");
12881284
this.syncstring_table = await this.synctable(query, []);
12891285
if (this.ephemeral && this.client.is_project()) {
1290-
this.syncstring_table.set({
1291-
string_id: this.string_id,
1292-
project_id: this.project_id,
1293-
path: this.path,
1286+
await this.set_syncstring_table({
12941287
doctype: JSON.stringify(this.doctype),
12951288
});
1296-
await this.syncstring_table.save();
12971289
} else {
12981290
dbg("waiting for, then handling the first update...");
12991291
await this.handle_syncstring_update();
@@ -1934,13 +1926,9 @@ export class SyncDoc extends EventEmitter {
19341926
*/
19351927
public set_settings = async (obj): Promise<void> => {
19361928
this.assert_is_ready("set_settings");
1937-
this.syncstring_table.set({
1938-
string_id: this.string_id,
1939-
project_id: this.project_id,
1940-
path: this.path,
1929+
await this.set_syncstring_table({
19411930
settings: obj,
19421931
});
1943-
await this.syncstring_table.save();
19441932
};
19451933

19461934
client_id = () => {
@@ -2179,13 +2167,9 @@ export class SyncDoc extends EventEmitter {
21792167
}
21802168

21812169
if (this.state != "ready") return;
2182-
this.syncstring_table.set({
2183-
string_id: this.string_id,
2184-
project_id: this.project_id,
2185-
path: this.path,
2170+
await this.set_syncstring_table({
21862171
last_snapshot: time,
21872172
});
2188-
await this.syncstring_table.save();
21892173
this.last_snapshot = time;
21902174
}
21912175

@@ -2351,10 +2335,7 @@ export class SyncDoc extends EventEmitter {
23512335
};
23522336

23532337
public set_snapshot_interval = async (n: number): Promise<void> => {
2354-
this.syncstring_table.set({
2355-
string_id: this.string_id,
2356-
project_id: this.project_id,
2357-
path: this.path,
2338+
await this.set_syncstring_table({
23582339
snapshot_interval: n,
23592340
});
23602341
await this.syncstring_table.save();
@@ -2558,13 +2539,9 @@ export class SyncDoc extends EventEmitter {
25582539
if (this.my_user_id === -1) {
25592540
this.my_user_id = this.users.length;
25602541
this.users.push(client_id);
2561-
this.syncstring_table.set({
2562-
string_id: this.string_id,
2563-
project_id: this.project_id,
2564-
path: this.path,
2542+
await this.set_syncstring_table({
25652543
users: this.users,
25662544
});
2567-
await this.syncstring_table.save();
25682545
}
25692546

25702547
this.emit("metadata-change");
@@ -2743,24 +2720,15 @@ export class SyncDoc extends EventEmitter {
27432720
this.assert_table_is_ready("syncstring");
27442721
// set timestamp of when the save happened; this can be useful
27452722
// for coordinating running code, etc.... and is just generally useful.
2746-
this.syncstring_table.set({
2747-
string_id: this.string_id,
2748-
project_id: this.project_id,
2749-
path: this.path,
2750-
save,
2751-
});
2752-
await this.syncstring_table.save();
2723+
if (!save.time) {
2724+
save.time = Date.now();
2725+
}
2726+
await this.set_syncstring_table({ save });
27532727
};
27542728

27552729
private set_read_only = async (read_only: boolean): Promise<void> => {
27562730
this.assert_table_is_ready("syncstring");
2757-
this.syncstring_table.set({
2758-
string_id: this.string_id,
2759-
project_id: this.project_id,
2760-
path: this.path,
2761-
read_only,
2762-
});
2763-
await this.syncstring_table.save();
2731+
await this.set_syncstring_table({ read_only });
27642732
};
27652733

27662734
public is_read_only = (): boolean => {
@@ -3323,4 +3291,19 @@ export class SyncDoc extends EventEmitter {
33233291
// with a nested for loop of sets. Doing it this way, massively
33243292
// simplifies client code.
33253293
emit_change_debounced = debounce(this.emit_change.bind(this), 0);
3294+
3295+
private set_syncstring_table = async (obj, save = true) => {
3296+
let value = this.syncstring_table_get_one();
3297+
const value0 = value;
3298+
for (const key in obj) {
3299+
value = value.set(key, obj[key]);
3300+
}
3301+
if (value0.equals(value)) {
3302+
return;
3303+
}
3304+
this.syncstring_table.set(value);
3305+
if (save) {
3306+
await this.syncstring_table.save();
3307+
}
3308+
};
33263309
}

src/packages/util/smc-version.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
/* autogenerated by the update_version script */
2-
exports.version=1726202900;
2+
exports.version=1727277632;

0 commit comments

Comments
 (0)