mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-03-30 15:08:28 +00:00
refactor: Pin verified entry.
This commit is contained in:
parent
6f3b605174
commit
03f0b1141e
@ -75,9 +75,10 @@ const OplogIndex = async ({ logHeads, entryStorage, headsStorage, indexStorage,
|
||||
/* 4. Add missing entries to the index (=to the log) */
|
||||
for (const hash of hashes) {
|
||||
await _index.put(hash, true)
|
||||
const bytes = await getBytes(hash)
|
||||
/* 5. Add new entry to entries (for pinning) */
|
||||
await _entries.put(hash, bytes)
|
||||
if (_entries.persist) {
|
||||
await _entries.persist(hash)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -114,6 +114,16 @@ const ComposedStorage = async (storage1, storage2) => {
|
||||
await storage2.clear()
|
||||
}
|
||||
|
||||
const persist = async (hash) => {
|
||||
if (storage1.persist) {
|
||||
await storage1.persist(hash)
|
||||
}
|
||||
|
||||
if (storage2.persist) {
|
||||
await storage2.persist(hash)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls close on each of the composed storages.
|
||||
* @function
|
||||
@ -129,6 +139,7 @@ const ComposedStorage = async (storage1, storage2) => {
|
||||
put,
|
||||
get,
|
||||
del,
|
||||
persist,
|
||||
iterator,
|
||||
merge,
|
||||
clear,
|
||||
|
@ -41,9 +41,7 @@ const IPFSBlockStorage = async ({ ipfs, pin, timeout } = {}) => {
|
||||
const { signal } = new TimeoutController(timeout || DefaultTimeout)
|
||||
await ipfs.blockstore.put(cid, data, { signal })
|
||||
|
||||
if (pin && !(await ipfs.pins.isPinned(cid))) {
|
||||
await drain(ipfs.pins.add(cid))
|
||||
}
|
||||
await persist(hash)
|
||||
}
|
||||
|
||||
const del = async (hash) => {}
|
||||
@ -65,6 +63,13 @@ const IPFSBlockStorage = async ({ ipfs, pin, timeout } = {}) => {
|
||||
}
|
||||
}
|
||||
|
||||
const persist = async (hash) => {
|
||||
const cid = CID.parse(hash, base58btc)
|
||||
if (pin && !(await ipfs.pins.isPinned(cid))) {
|
||||
await drain(ipfs.pins.add(cid))
|
||||
}
|
||||
}
|
||||
|
||||
const iterator = async function * () {}
|
||||
|
||||
const merge = async (other) => {}
|
||||
@ -77,6 +82,7 @@ const IPFSBlockStorage = async ({ ipfs, pin, timeout } = {}) => {
|
||||
put,
|
||||
del,
|
||||
get,
|
||||
persist,
|
||||
iterator,
|
||||
merge,
|
||||
clear,
|
||||
|
Loading…
x
Reference in New Issue
Block a user