mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-13 15:14:52 +09:00
Implement autosaving of data held in memory
Add controller.autosave_interval config that specifies the frequency which controller config, hosts, instances, users, mod packs and plugin specific data which is held in memory should be automatically flushed to disk if they have changed since the last time they were saved. This prevents data loss in the event of a server crash. Plugins can use the onSaveData hook to save its own data at the same time as the controller does and this obsoletes making an autosave interval in the plugin. Resolves #523.
This commit is contained in:
1 parent
faadf873fb
commit
ffe5040644
14 files changed
+168
-57
No files matched your search
@@ -10,6 +10,7 @@ import * as lib from "@clusterio/lib";
|
||||
export default class UserManager {
|
||||
roles: Map<number, lib.Role> = new Map();
|
||||
users: Map<string, lib.User> = new Map();
|
||||
dirty = false;
|
||||
|
||||
constructor(
|
||||
private _config: lib.ControllerConfig
|
||||
@@ -41,10 +42,6 @@ export default class UserManager {
|
||||
}
|
||||
|
||||
async save(filePath:string): Promise<void> {
|
||||
if (this.roles.size === 0 || this.users.size === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
let serializedRoles = [];
|
||||
for (let role of this.roles.values()) {
|
||||
serializedRoles.push(role.serialize());
|
||||
@@ -59,6 +56,7 @@ export default class UserManager {
|
||||
users: serializedUsers,
|
||||
roles: serializedRoles,
|
||||
};
|
||||
this.dirty = false;
|
||||
await lib.safeOutputFile(filePath, JSON.stringify(serialized, null, "\t"));
|
||||
}
|
||||
|
||||
@@ -80,6 +78,7 @@ export default class UserManager {
|
||||
|
||||
let user = new lib.User({ name, roles }, this.roles);
|
||||
this.users.set(name, user);
|
||||
this.dirty = true;
|
||||
return user;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user