Software /
code /
prosody-modules
Diff
mod_storage_appendmap/mod_storage_appendmap.lua @ 5856:75dee6127829
Merge upstream
author | Trần H. Trung <xmpp:trần.h.trung@trung.fun> |
---|---|
date | Tue, 06 Feb 2024 18:32:01 +0700 (17 months ago) |
parent | 5714:78f766372e2c |
line wrap: on
line diff
--- a/mod_storage_appendmap/mod_storage_appendmap.lua Tue Aug 29 23:51:17 2023 +0700 +++ b/mod_storage_appendmap/mod_storage_appendmap.lua Tue Feb 06 18:32:01 2024 +0700 @@ -1,11 +1,13 @@ local dump = require "util.serialization".serialize; local load = require "util.envload".envloadfile; +local datetime = require "util.datetime".datetime; local dm = require "core.storagemanager".olddm; local REMOVE = {}; -- Special value for removing keys local driver = {}; +local timestamps = module:get_option_boolean("appendmap_timestamps", true); local keywords = { ["do"] = true; ["and"] = true; ["else"] = true; ["break"] = true; @@ -82,6 +84,9 @@ function map:set_keys(user, keyvalues) local data = serialize_map(keyvalues); + if timestamps then + data = "-- " .. datetime() .. "\n" .. data; + end return dm.append_raw(user, module.host, self.store, "map", data); end @@ -94,9 +99,16 @@ return os.remove(filename); end local data = serialize_pair(key, value); + if timestamps then + data = "-- " .. datetime() .. "\n" .. data; + end return dm.append_raw(user, module.host, self.store, "map", data); end +function map:items() + return dm.users(module.host, self.store, "map"); +end + local keyval = { remove = REMOVE }; local keyval_mt = { __index = keyval }; @@ -106,9 +118,16 @@ function keyval:set(user, keyvalues) local data = serialize_map(keyvalues); + if timestamps then + data = "-- " .. datetime() .. "\n" .. data; + end return dm.store_raw(dm.getpath(user, module.host, self.store, "map"), data); end +function keyval:users() + return dm.users(module.host, self.store, "map"); +end + -- TODO some kind of periodic compaction thing? function map:_compact(user) local data = self:get(user);