mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-06-23 22:42:30 +00:00
Add ts to db op
This commit is contained in:
parent
5706090f35
commit
6db0ac79be
@ -20,18 +20,16 @@ class OperationsLog {
|
|||||||
const entry = {
|
const entry = {
|
||||||
op: operation,
|
op: operation,
|
||||||
key: key,
|
key: key,
|
||||||
value: value
|
value: value,
|
||||||
|
meta: {
|
||||||
|
ts: new Date().getTime()
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let node, logHash;
|
let node, logHash;
|
||||||
return this._log.add(entry)
|
return this._log.add(entry)
|
||||||
.then((op) => node = op)
|
.then((op) => node = op)
|
||||||
.then(() => {
|
.then(() => this._padOperation(node))
|
||||||
// Add the hash of the log entry to the payload
|
|
||||||
Object.assign(node.payload, { hash: node.hash });
|
|
||||||
if(node.payload.key === null)
|
|
||||||
Object.assign(node.payload, { key: node.hash });
|
|
||||||
})
|
|
||||||
.then(() => Log.getIpfsHash(this._ipfs, this._log))
|
.then(() => Log.getIpfsHash(this._ipfs, this._log))
|
||||||
.then((hash) => logHash = hash)
|
.then((hash) => logHash = hash)
|
||||||
.then(() => this._lastWrite = logHash)
|
.then(() => this._lastWrite = logHash)
|
||||||
@ -58,12 +56,20 @@ class OperationsLog {
|
|||||||
.then((other) => this._log.join(other))
|
.then((other) => this._log.join(other))
|
||||||
.then((merged) => newItems = merged)
|
.then((merged) => newItems = merged)
|
||||||
.then(() => Cache.set(this.dbname, hash))
|
.then(() => Cache.set(this.dbname, hash))
|
||||||
.then(() => newItems.map((f) => f.payload))
|
.then(() => newItems.map((f) => this._padOperation(f)))
|
||||||
|
.then((items) => items.map((f) => f.payload))
|
||||||
}
|
}
|
||||||
|
|
||||||
delete() {
|
delete() {
|
||||||
this._log.clear();
|
this._log.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_padOperation(node) {
|
||||||
|
Object.assign(node.payload, { hash: node.hash });
|
||||||
|
if(node.payload.key === null)
|
||||||
|
Object.assign(node.payload, { key: node.hash });
|
||||||
|
return node;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = OperationsLog;
|
module.exports = OperationsLog;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user