Skip to content

Commit 16377df

Browse files
committed
add config options for speeding up tests
1 parent 93ca3c1 commit 16377df

File tree

11 files changed

+41
-35
lines changed

11 files changed

+41
-35
lines changed

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,9 @@ const Plugin = require('ssb-db2/indexes/plugin')
205205
// This is a secret-stack plugin
206206
exports.init = function (sbot, config) {
207207
class MyIndex extends Plugin {
208-
constructor(log, dir) {
209-
// log, dir, name, version, keyEncoding, valueEncoding
210-
super(log, dir, 'myindex', 1, 'utf8', 'json')
208+
constructor(log, dir, configDb2) {
209+
// log, dir, name, version, keyEncoding, valueEncoding, configDb2
210+
super(log, dir, 'myindex', 1, 'utf8', 'json', configDb2)
211211
}
212212

213213
processRecord(record, seq) {
@@ -242,6 +242,7 @@ There are three parts you'll always need:
242242
- `version`, upon changing, will cause a full rebuild of this index
243243
- `keyEncoding` and `valueEncoding` must be strings from
244244
[level-codec]
245+
- `configDb2` is the db2 part of the config - `config.db2`
245246
- `processRecord`: here you handle a msg (in [bipf]) and potentially
246247
write something to the index using
247248
`this.batch.push(leveldbOperation)`
@@ -704,6 +705,11 @@ const config = {
704705
* Default: 90
705706
*/
706707
maxCpuWait: 90,
708+
709+
710+
flushDebounce: 250,
711+
712+
writeTimeout: 250,
707713
},
708714
}
709715
```

core.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ const {
4545
deferred,
4646
asOffsets,
4747
isEncrypted,
48-
toCallback,
4948
batch,
5049
toPullStream,
5150
} = operators
@@ -812,7 +811,7 @@ exports.init = function (sbot, config) {
812811
}
813812

814813
function registerIndex(Index) {
815-
const index = new Index(log, dir)
814+
const index = new Index(log, dir, config.db2)
816815

817816
if (indexes[index.name]) throw 'Index already exists'
818817

indexes/about-self.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55
// DEPRECATED
66
// please use https://github.com/ssbc/ssb-about-self
77
module.exports = require('ssb-about-self/plugin.js')
8+
9+
// TODO patch this module to also take configDb2

indexes/base.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ const BIPF_OOO = bipf.allocAndEncode('ooo')
1717
// Necessary for feed validation and for EBT
1818
module.exports = function makeBaseIndex(privateIndex) {
1919
return class BaseIndex extends Plugin {
20-
constructor(log, dir) {
21-
super(log, dir, 'base', 2, undefined, 'json')
20+
constructor(log, dir, configDb2) {
21+
super(log, dir, 'base', 2, undefined, 'json', configDb2)
2222
this.privateIndex = privateIndex
2323
this.feedLatest = new Map()
2424
}

indexes/ebt.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ const BIPF_SEQUENCE = bipf.allocAndEncode('sequence')
1111

1212
// [feedId, sequence] => offset
1313
module.exports = class EBT extends Plugin {
14-
constructor(log, dir) {
15-
super(log, dir, 'ebt', 1, 'json')
14+
constructor(log, dir, configDb2) {
15+
super(log, dir, 'ebt', 1, 'json', null, configDb2)
1616
}
1717

1818
processRecord(record, seq, pValue) {

indexes/full-mentions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ function parseInt10(x) {
1818

1919
// [destMsgId, origShortMsgId] => seq
2020
module.exports = class FullMentions extends Plugin {
21-
constructor(log, dir) {
22-
super(log, dir, 'fullMentions', 1, 'json')
21+
constructor(log, dir, configDb2) {
22+
super(log, dir, 'fullMentions', 1, 'json', null, configDb2)
2323
}
2424

2525
processRecord(record, seq, pValue) {

indexes/keys.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ const BIPF_KEY = bipf.allocAndEncode('key')
99

1010
// msgId => seq
1111
module.exports = class Keys extends Plugin {
12-
constructor(log, dir) {
13-
super(log, dir, 'keys', 1)
12+
constructor(log, dir, configDb2) {
13+
super(log, dir, 'keys', 1, null, null, configDb2)
1414
}
1515

1616
processRecord(record, seq, pValue) {

indexes/plugin.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function thenMaybeReportError(err) {
2424
}
2525

2626
module.exports = class Plugin {
27-
constructor(log, dir, name, version, keyEncoding, valueEncoding) {
27+
constructor(log, dir, name, version, keyEncoding, valueEncoding, configDb2) {
2828
this.log = log
2929
this.name = name
3030
this.levelPutListeners = []
@@ -108,7 +108,8 @@ module.exports = class Plugin {
108108
*/
109109
this.forcedFlush = this._flush.bind(this, true)
110110

111-
const liveFlush = debounce(this.flush, 250)
111+
const flushDebounce = (configDb2 && configDb2.flushDebounce) || 250
112+
const liveFlush = debounce(this.flush, flushDebounce)
112113

113114
this.onRecord = function onRecord(record, isLive, pValue) {
114115
let changes = 0

indexes/private.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ const multicb = require('multicb')
1111
const NumsFile = require('../nums-file')
1212
const { indexesPath } = require('../defaults')
1313

14+
// NOTE this index is not based on indexes/plugin.js - it sits lower in the
15+
// stack so has a different signature and is not registered with
16+
// ssb.db.registerPlugin
17+
1418
module.exports = function (dir, sbot, config) {
1519
const latestOffset = Obv()
1620
const stateLoaded = DeferredPromise()

log.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ module.exports = function (dir, config, privateIndex, db) {
2424
return false
2525
}
2626
},
27+
writeTimeout: config.db2.writeTimeout,
2728
})
2829

2930
log.add = function (key, value, feedId, encoding, isOOO, cb) {

0 commit comments

Comments
 (0)