Merge pull request #1225 from orbitdb/feat/encryption-pin-oplog-entry

refactor: Pin verified entry.
This commit is contained in:
Hayden Young 2025-04-12 08:41:23 +01:00 committed by GitHub
commit c3d8b37915
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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) */ /* 4. Add missing entries to the index (=to the log) */
for (const hash of hashes) { for (const hash of hashes) {
await _index.put(hash, true) await _index.put(hash, true)
const bytes = await getBytes(hash)
/* 5. Add new entry to entries (for pinning) */ /* 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() 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. * Calls close on each of the composed storages.
* @function * @function
@ -129,6 +139,7 @@ const ComposedStorage = async (storage1, storage2) => {
put, put,
get, get,
del, del,
persist,
iterator, iterator,
merge, merge,
clear, clear,

View File

@ -41,9 +41,7 @@ const IPFSBlockStorage = async ({ ipfs, pin, timeout } = {}) => {
const { signal } = new TimeoutController(timeout || DefaultTimeout) const { signal } = new TimeoutController(timeout || DefaultTimeout)
await ipfs.blockstore.put(cid, data, { signal }) await ipfs.blockstore.put(cid, data, { signal })
if (pin && !(await ipfs.pins.isPinned(cid))) { await persist(hash)
await drain(ipfs.pins.add(cid))
}
} }
const del = async (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 iterator = async function * () {}
const merge = async (other) => {} const merge = async (other) => {}
@ -77,6 +82,7 @@ const IPFSBlockStorage = async ({ ipfs, pin, timeout } = {}) => {
put, put,
del, del,
get, get,
persist,
iterator, iterator,
merge, merge,
clear, clear,