Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can declare writers as blind #201

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading