From 574230f0d1659cf5be974a90d144d13baa0281f3 Mon Sep 17 00:00:00 2001 From: "Marshall T. Rose" Date: Wed, 29 Mar 2017 12:42:03 -0700 Subject: [PATCH] Use ledger-client@0.9.8 to support excludeOnly option Fixes https://github.com/brave/browser-laptop/issues/7940 --- app/ledger.js | 47 ++++++++++++++++++++++++++++++++++++++++++----- package.json | 2 +- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/app/ledger.js b/app/ledger.js index 61d7197f7d1..cb68d73bb18 100644 --- a/app/ledger.js +++ b/app/ledger.js @@ -1232,6 +1232,8 @@ var excludeP = (publisher, callback) => { if (callback) callback(err, result) } + if (!v2RulesetDB) return setTimeout(() => { excludeP(publisher, callback) }, 5 * msecs.second) + inspectP(v2RulesetDB, v2RulesetPath, publisher, 'exclude', 'domain:' + publisher, (err, result) => { var props @@ -1495,16 +1497,26 @@ var callback = (err, result, delayTime) => { entries = [] results.forEach((entry) => { - entries.push({ type: 'put', - key: entry.facet + ':' + entry.publisher, - value: JSON.stringify(underscore.omit(entry, [ 'facet', 'publisher' ])) - }) + var key = entry.facet + ':' + entry.publisher + + if (entry.exclude !== false) { + entries.push({ type: 'put', key: key, value: JSON.stringify(underscore.omit(entry, [ 'facet', 'publisher' ])) }) + } else { + entries.push({ type: 'del', key: key }) + } }) v2RulesetDB.batch(entries, (err) => { if (err) return console.log(v2RulesetPath + ' error: ' + JSON.stringify(err, null, 2)) - underscore.keys(synopsis.publishers).forEach((publisher) => { excludeP(publisher) }) + if (entries.length === 0) return + + underscore.keys(synopsis.publishers).forEach((publisher) => { +// be safe... + if (synopsis.publishers[publisher]) delete synopsis.publishers[publisher].options.exclude + + excludeP(publisher) + }) }) } if (result.publishersV2) { @@ -1701,6 +1713,31 @@ var run = (delayTime) => { * ledger client utilities */ +/* code that may never be needed... + +var rulesV2Reset = (callback) => { + if (clientOptions.verboseP) console.log('\n\nreset rulesets') + if (!v2RulesetDB) return + + if (client) { + delete client.state.rulesV2Stamp + client.state.updatesStamp = underscore.now() + } + v2RulesetDB.close((err) => { + if (err) console.log(v2RulesetPath + ' close error: ' + err.toString()) + + v2RulesetDB = null + require('leveldown').destroy(pathName(v2RulesetPath), (err) => { + if (err) console.log(v2RulesetPath + ' destroy error: ' + err.toString()) + + v2RulesetDB = levelup(pathName(v2RulesetPath)) + callback() + }) + }) +} + +*/ + var getStateInfo = (state) => { var ballots, i, transaction var info = state.paymentInfo diff --git a/package.json b/package.json index 735a2c950df..60a3f8c7a53 100644 --- a/package.json +++ b/package.json @@ -104,7 +104,7 @@ "keytar": "^3.0.0", "l20n": "^3.5.1", "ledger-balance": "^0.8.64", - "ledger-client": "^0.9.7", + "ledger-client": "^0.9.8", "ledger-geoip": "^0.8.75", "ledger-publisher": "^0.9.0", "lru-cache": "^1.0.0",