diff --git a/src/oplog/oplog-index.js b/src/oplog/oplog-index.js index 68509a0..8fd67b0 100644 --- a/src/oplog/oplog-index.js +++ b/src/oplog/oplog-index.js @@ -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) + } } } diff --git a/src/storage/composed.js b/src/storage/composed.js index 91b9b8d..5c35309 100644 --- a/src/storage/composed.js +++ b/src/storage/composed.js @@ -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, diff --git a/src/storage/ipfs-block.js b/src/storage/ipfs-block.js index a1c4acc..c0b823b 100644 --- a/src/storage/ipfs-block.js +++ b/src/storage/ipfs-block.js @@ -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,