mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-07-02 18:42:31 +00:00
Cached default storage for Database
This commit is contained in:
parent
27b4885d8e
commit
0bc17bd9f5
@ -2,19 +2,28 @@ import { EventEmitter } from 'events'
|
||||
import PQueue from 'p-queue'
|
||||
import Path from 'path'
|
||||
import Sync from './sync.js'
|
||||
import { IPFSBlockStorage, LevelStorage } from './storage/index.js'
|
||||
import { ComposedStorage, LRUStorage, MemoryStorage, IPFSBlockStorage, LevelStorage } from './storage/index.js'
|
||||
|
||||
const defaultPointerCount = 16
|
||||
const defaultPointerCount = 0
|
||||
const defaultCacheSize = 1000
|
||||
|
||||
const Database = async ({ OpLog, ipfs, identity, address, name, accessController, directory, storage, headsStorage, pointerCount }) => {
|
||||
const { Log, Entry } = OpLog
|
||||
|
||||
const entryStorage = storage || await IPFSBlockStorage({ ipfs, pin: true })
|
||||
directory = Path.join(directory || './orbitdb', `./${address}/`)
|
||||
pointerCount = pointerCount || defaultPointerCount
|
||||
|
||||
directory = Path.join(directory || './orbitdb', `./${address.path}/`)
|
||||
headsStorage = headsStorage || await LevelStorage({ path: Path.join(directory, '/log/_heads/') })
|
||||
const entryStorage = await ComposedStorage(
|
||||
await LRUStorage({ size: defaultCacheSize }),
|
||||
await IPFSBlockStorage({ ipfs, pin: true })
|
||||
)
|
||||
|
||||
const log = await Log(identity, { logId: address.toString(), access: accessController, entryStorage, headsStorage })
|
||||
headsStorage = await ComposedStorage(
|
||||
await LRUStorage({ size: defaultCacheSize }),
|
||||
await LevelStorage({ path: Path.join(directory, '/log/_heads/') })
|
||||
)
|
||||
|
||||
const log = await Log(identity, { logId: address, access: accessController, entryStorage, headsStorage })
|
||||
|
||||
// const indexStorage = await LevelStorage({ path: Path.join(directory, '/log/_index/') })
|
||||
// const log = await Log(identity, { logId: address.toString(), access: accessController, entryStorage, headsStorage, indexStorage })
|
||||
@ -22,8 +31,6 @@ const Database = async ({ OpLog, ipfs, identity, address, name, accessController
|
||||
const events = new EventEmitter()
|
||||
const queue = new PQueue({ concurrency: 1 })
|
||||
|
||||
pointerCount = pointerCount || defaultPointerCount
|
||||
|
||||
const addOperation = async (op) => {
|
||||
const task = async () => {
|
||||
const entry = await log.append(op, { pointerCount })
|
||||
@ -55,7 +62,6 @@ const Database = async ({ OpLog, ipfs, identity, address, name, accessController
|
||||
events.emit('close')
|
||||
}
|
||||
|
||||
// TODO: rename to clear()
|
||||
const drop = async () => {
|
||||
await queue.onIdle()
|
||||
await log.clear()
|
||||
|
Loading…
x
Reference in New Issue
Block a user