mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-07-01 10:12:29 +00:00
Process appends and joins through a queue
This commit is contained in:
parent
734f50ed7e
commit
16b3358355
@ -7,6 +7,7 @@
|
||||
* ["Merkle-CRDTs: Merkle-DAGs meet CRDTs"]{@link https://arxiv.org/abs/2004.00107}
|
||||
*/
|
||||
import LRU from 'lru'
|
||||
import PQueue from 'p-queue'
|
||||
import Entry from './entry.js'
|
||||
import Clock, { tickClock } from './clock.js'
|
||||
import Heads from './heads.js'
|
||||
@ -81,6 +82,9 @@ const Log = async (identity, { logId, logHeads, access, entryStorage, headsStora
|
||||
const _heads = await Heads({ storage: headsStorage, heads: logHeads })
|
||||
// Conflict-resolution sorting function
|
||||
sortFn = NoZeroes(sortFn || LastWriteWins)
|
||||
// Internal queues for processing appends and joins in their call-order
|
||||
const appendQueue = new PQueue({ concurrency: 1 })
|
||||
const joinQueue = new PQueue({ concurrency: 1 })
|
||||
|
||||
/**
|
||||
* Returns the clock of the log.
|
||||
@ -153,6 +157,7 @@ const Log = async (identity, { logId, logHeads, access, entryStorage, headsStora
|
||||
* @instance
|
||||
*/
|
||||
const append = async (data, options = { referencesCount: 0 }) => {
|
||||
const task = async () => {
|
||||
// 1. Prepare entry
|
||||
// 2. Authorize entry
|
||||
// 3. Store entry
|
||||
@ -189,6 +194,9 @@ const Log = async (identity, { logId, logHeads, access, entryStorage, headsStora
|
||||
return entry
|
||||
}
|
||||
|
||||
return appendQueue.add(task)
|
||||
}
|
||||
|
||||
/**
|
||||
* Join two logs.
|
||||
*
|
||||
@ -232,6 +240,7 @@ const Log = async (identity, { logId, logHeads, access, entryStorage, headsStora
|
||||
* @instance
|
||||
*/
|
||||
const joinEntry = async (entry) => {
|
||||
const task = async () => {
|
||||
/* 1. Check if the entry is already in the log and return early if it is */
|
||||
const isAlreadyInTheLog = await has(entry.hash)
|
||||
if (isAlreadyInTheLog) {
|
||||
@ -309,6 +318,9 @@ const Log = async (identity, { logId, logHeads, access, entryStorage, headsStora
|
||||
return true
|
||||
}
|
||||
|
||||
return joinQueue.add(task)
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* @memberof module:Log~Log
|
||||
|
Loading…
x
Reference in New Issue
Block a user