Skip to Content
Motoko

Recovering and erasing on this host

A SQLite file records nothing of what its last instance left, so sqliteScopes(directory), the unfinished() of sqliteStore({ directory }), lists every scope that has a file. runtime.recover() opens each, which carries on whatever it left, and with closeIdleAfterMs the ones with nothing to do close again once idle. Fine for an app with a handful of instances, as an Electron app has; a server with many instances per file directory pays one open each at every recover().

eraseSqliteConversations(file, conversations) is what sqliteStore erases deleted sessions with: each conversation, the conversations its tasks made, and their entries, tasks, submissions and documents, in one transaction on a connection of its own, while the instance's storage is closed. The statements are eraseConversations of @chia1104/motoko-core/sqlite, which write pi-durable's tables directly, against its SQLite schema version 2 (pi-durable 1.6), and refuse a file in any other version, changing nothing. Around them it turns on SQLite's secure_delete and truncates the write-ahead log, so the erased text is overwritten in the file, not only unlinked. The deleted session's title, first message and metadata, which the sessions record held, went when it was deleted: that commit drops the record's earlier revisions, and the open file overwrites them. A conversation that still has unfinished work, or that another conversation forks from, is left for the next close.