From 89ff328325dec53ae92018498d556154c175771b Mon Sep 17 00:00:00 2001 From: haad Date: Wed, 30 Oct 2024 10:42:15 +0100 Subject: [PATCH 1/2] Test --- src/manifest-store.js | 6 +++++- src/oplog/log.js | 2 ++ src/orbitdb.js | 5 +++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/manifest-store.js b/src/manifest-store.js index 129b4d8..23225d1 100644 --- a/src/manifest-store.js +++ b/src/manifest-store.js @@ -16,13 +16,17 @@ const ManifestStore = async ({ ipfs, storage } = {}) => { */ storage = storage || await ComposedStorage( - await LRUStorage({ size: 1000 }), + await LRUStorage({ size: 100000 }), await IPFSBlockStorage({ ipfs, pin: true }) ) const get = async (address) => { const bytes = await storage.get(address) const { value } = await Block.decode({ bytes, codec, hasher }) + if (value) { + // Write to storage to make sure it gets pinned on IPFS + await storage.put(address, bytes) + } return value } diff --git a/src/oplog/log.js b/src/oplog/log.js index 4c5fff6..2035839 100644 --- a/src/oplog/log.js +++ b/src/oplog/log.js @@ -315,6 +315,8 @@ const Log = async (identity, { logId, logHeads, access, entryStorage, headsStora /* 6. Add the new entry to heads (=union with current heads) */ await _heads.add(entry) + await _entries.put(entry.hash, entry.bytes) + return true } diff --git a/src/orbitdb.js b/src/orbitdb.js index c87791c..753f08e 100644 --- a/src/orbitdb.js +++ b/src/orbitdb.js @@ -122,13 +122,16 @@ const OrbitDB = async ({ ipfs, id, identity, identities, directory } = {}) => { if (isValidAddress(address)) { // If the address given was a valid OrbitDB address, eg. '/orbitdb/zdpuAuK3BHpS7NvMBivynypqciYCuy2UW77XYBPUYRnLjnw13' const addr = OrbitDBAddress(address) + console.log(1) manifest = await manifestStore.get(addr.hash) const acType = manifest.accessController.split('/', 2).pop() AccessController = getAccessController(acType)() + console.log(2) accessController = await AccessController({ orbitdb: { open, identity, ipfs }, identities, address: manifest.accessController }) name = manifest.name type = type || manifest.type meta = manifest.meta + console.log(3) } else { // If the address given was not valid, eg. just the name of the database type = type || DefaultDatabaseType @@ -153,12 +156,14 @@ const OrbitDB = async ({ ipfs, id, identity, identities, directory } = {}) => { address = address.toString() + console.log(4) const db = await Database({ ipfs, identity, address, name, access: accessController, directory, meta, syncAutomatically: sync, headsStorage, entryStorage, indexStorage, referencesCount }) db.events.on('close', onDatabaseClosed(address)) databases[address] = db + console.log(5) return db } From 4a5822c4a131d85c982cf57b4384cfd2ab1e0058 Mon Sep 17 00:00:00 2001 From: Hayden Young Date: Thu, 31 Oct 2024 22:48:11 +0000 Subject: [PATCH 2/2] fix: Remove console output. --- src/orbitdb.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/orbitdb.js b/src/orbitdb.js index 753f08e..c87791c 100644 --- a/src/orbitdb.js +++ b/src/orbitdb.js @@ -122,16 +122,13 @@ const OrbitDB = async ({ ipfs, id, identity, identities, directory } = {}) => { if (isValidAddress(address)) { // If the address given was a valid OrbitDB address, eg. '/orbitdb/zdpuAuK3BHpS7NvMBivynypqciYCuy2UW77XYBPUYRnLjnw13' const addr = OrbitDBAddress(address) - console.log(1) manifest = await manifestStore.get(addr.hash) const acType = manifest.accessController.split('/', 2).pop() AccessController = getAccessController(acType)() - console.log(2) accessController = await AccessController({ orbitdb: { open, identity, ipfs }, identities, address: manifest.accessController }) name = manifest.name type = type || manifest.type meta = manifest.meta - console.log(3) } else { // If the address given was not valid, eg. just the name of the database type = type || DefaultDatabaseType @@ -156,14 +153,12 @@ const OrbitDB = async ({ ipfs, id, identity, identities, directory } = {}) => { address = address.toString() - console.log(4) const db = await Database({ ipfs, identity, address, name, access: accessController, directory, meta, syncAutomatically: sync, headsStorage, entryStorage, indexStorage, referencesCount }) db.events.on('close', onDatabaseClosed(address)) databases[address] = db - console.log(5) return db }