refactor: Pin verified entry.

This commit is contained in:
Hayden Young 2025-03-07 12:25:02 +01:00
parent 6f3b605174
commit 03f0b1141e
3 changed files with 23 additions and 5 deletions

View File

@ -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)
}
}
}

View File

@ -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,

View File

@ -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,