mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-06-02 20:26:37 +00:00
Cleanup OrbitDB
This commit is contained in:
parent
5d8f477981
commit
431e102808
@ -133,12 +133,27 @@ class OrbitDB {
|
|||||||
|
|
||||||
/* Private methods */
|
/* Private methods */
|
||||||
|
|
||||||
|
// Cache DB operation entries in memory from a log
|
||||||
|
_cacheOperations(log) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const payloadHashes = log.items
|
||||||
|
.map((f) => f.payload)
|
||||||
|
.filter((f) => Lazy(this._cached).find((e) => e.hash === f.payload) === undefined);
|
||||||
|
|
||||||
|
Promise.map(payloadHashes, (f) => OrbitDB.fetchPayload(this._ipfs, f), { concurrency: 4 })
|
||||||
|
.then((payloads) => {
|
||||||
|
payloads.forEach((f) => this._cached.push(f));
|
||||||
|
resolve();
|
||||||
|
})
|
||||||
|
.catch(reject);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// LWW-element-set
|
// LWW-element-set
|
||||||
_read(sequence, key, amount, inclusive) {
|
_read(sequence, key, amount, inclusive) {
|
||||||
// Last-Write-Wins, ie. use only the first occurance of the key
|
// Last-Write-Wins, ie. use only the first occurance of the key
|
||||||
let handled = [];
|
let handled = [];
|
||||||
const _createLWWSet = (item) => {
|
const _createLWWSet = (item) => {
|
||||||
// console.log("-->", item, handled)
|
|
||||||
if(Lazy(handled).indexOf(item.key) === -1) {
|
if(Lazy(handled).indexOf(item.key) === -1) {
|
||||||
handled.push(item.key);
|
handled.push(item.key);
|
||||||
if(DBOperation.Types.isInsert(item.op))
|
if(DBOperation.Types.isInsert(item.op))
|
||||||
@ -148,16 +163,13 @@ class OrbitDB {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Find the items from the sequence (list of operations)
|
// Find the items from the sequence (list of operations)
|
||||||
// console.log("333", this._cached)
|
|
||||||
return sequence
|
return sequence
|
||||||
.map((f) => Lazy(this._cached).find((e) => {
|
.map((f) => Lazy(this._cached).find((e) => {
|
||||||
// console.log("e", e, f)
|
|
||||||
return e.hash === f.payload
|
return e.hash === f.payload
|
||||||
}))
|
}))
|
||||||
.compact() // Remove nulls
|
.compact() // Remove nulls
|
||||||
.skipWhile((f) => key && f.key !== key) // Drop elements until we have the first one requested
|
.skipWhile((f) => key && f.key !== key) // Drop elements until we have the first one requested
|
||||||
.map((f) => {
|
.map((f) => {
|
||||||
// console.log("f", f, "key", key);
|
|
||||||
return f;
|
return f;
|
||||||
})
|
})
|
||||||
.map(_createLWWSet) // Return items as LWW (ignore values after the first found)
|
.map(_createLWWSet) // Return items as LWW (ignore values after the first found)
|
||||||
@ -188,22 +200,6 @@ class OrbitDB {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cache DB operation entries in memory from a log
|
|
||||||
_cacheOperations(log) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const payloadHashes = log.items
|
|
||||||
.map((f) => f.payload)
|
|
||||||
.filter((f) => Lazy(this._cached).find((e) => e.hash === f.payload) === undefined);
|
|
||||||
|
|
||||||
Promise.map(payloadHashes, (f) => OrbitDB.fetchPayload(this._ipfs, f), { concurrency: 4 })
|
|
||||||
.then((payloads) => {
|
|
||||||
payloads.forEach((f) => this._cached.push(f));
|
|
||||||
resolve();
|
|
||||||
})
|
|
||||||
.catch(reject);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
static fetchPayload(ipfs, hash) {
|
static fetchPayload(ipfs, hash) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
ipfs.object.get(hash)
|
ipfs.object.get(hash)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user