Skip to content

Commit

Permalink
can declare writers as blind
Browse files Browse the repository at this point in the history
  • Loading branch information
mafintosh committed Dec 15, 2024
1 parent 775699f commit 3c14c28
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1937,9 +1937,9 @@ module.exports = class Autobase extends ReadyResource {
}

// triggered from apply
async addWriter (key, { indexer = true, isIndexer = indexer } = {}) { // just compat for old version
async addWriter (key, { indexer = true, isIndexer = indexer, isBlind = false } = {}) { // just compat for old version
assert(this._applying !== null, 'System changes are only allowed in apply')
await this.system.add(key, { isIndexer })
await this.system.add(key, { isIndexer, isBlind })

const writer = (await this._getWriterByKey(key, -1, 0, false, true, null)) || this._makeWriter(key, 0, true, false)
await writer.ready()
Expand Down
3 changes: 2 additions & 1 deletion lib/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,14 +495,15 @@ const Member = {
c.uint.preencode(state, m.length)
},
encode (state, m) {
c.uint.encode(state, (m.isIndexer ? 1 : 0) | (m.isRemoved ? 2 : 0))
c.uint.encode(state, (m.isIndexer ? 1 : 0) | (m.isRemoved ? 2 : 0) | (m.isBlind ? 4 : 0))
c.uint.encode(state, m.length)
},
decode (state) {
const flags = c.uint.decode(state)
return {
isIndexer: (flags & 1) !== 0,
isRemoved: (flags & 2) !== 0,
isBlind: (flags & 4) !== 0,
length: c.uint.decode(state)
}
}
Expand Down
7 changes: 5 additions & 2 deletions lib/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ module.exports = class SystemView extends ReadyResource {
return this._clockUpdates.get(b4a.toString(key, 'hex')) || 0
}

async add (key, { isIndexer = false, length = this._seenLength(key) } = {}) {
async add (key, { isIndexer = false, isBlind = false, length = this._seenLength(key) } = {}) {
let wasTracked = false
let wasIndexer = false

Expand All @@ -300,6 +300,7 @@ module.exports = class SystemView extends ReadyResource {
await this._batch.put(key, {
isIndexer,
isRemoved: false,
isBlind,
length
}, {
valueEncoding: Member,
Expand All @@ -315,7 +316,7 @@ module.exports = class SystemView extends ReadyResource {

if (length === 0 && o.length) length = o.length

return o.isRemoved !== n.isRemoved || o.isIndexer !== n.isIndexer || o.length !== n.length
return o.isRemoved !== n.isRemoved || o.isIndexer !== n.isIndexer || o.length !== n.length || o.isBlind !== n.isBlind
}
})

Expand All @@ -337,11 +338,13 @@ module.exports = class SystemView extends ReadyResource {
let wasTracked = false

const node = await this._batch.get(key, { valueEncoding: Member, keyEncoding: MEMBERS })
const isBlind = node.value.isBlind
const length = node ? node.value.length : 0

await this._batch.put(key, {
isIndexer: false,
isRemoved: true,
isBlind,
length
}, {
valueEncoding: Member,
Expand Down

0 comments on commit 3c14c28

Please sign in to comment.