Skip to content

Commit 3114e2c

Browse files
author
Benjamin Forster
authored
Merge pull request #23 from e-e-e/reduce-stored-size
stop unnecessarily storing data in the value of db
2 parents 9ca8f5e + 8f2b1b6 commit 3114e2c

2 files changed

Lines changed: 6 additions & 7 deletions

File tree

lib/utils.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,8 @@ function keyIsAVariable (tripleKey) {
124124

125125
function extraDataMask (obj) {
126126
return Object.keys(obj)
127-
.filter(not(keyIsAVariable))
128127
.reduce((prev, key) => {
129-
prev[key] = obj[key]
128+
if(!keyIsAVariable(obj[key]) && !hasKey(key)) prev[key] = obj[key]
130129
return prev
131130
}, {})
132131
}

test/triple-store.spec.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -614,12 +614,12 @@ describe('generateBatch', function () {
614614
db.close(done)
615615
})
616616
it('should generate a batch from a triple with length 6', function () {
617-
var triple = { subject: 'a', predicate: 'b', object: 'c' }
617+
var triple = { subject: 'a', predicate: 'b', object: 'c', extra: 'data' }
618618
var ops = db._generateBatch(triple)
619619
expect(ops).to.have.property('length', 6)
620620
ops.forEach(function (op) {
621621
expect(op).to.have.property('type', 'put')
622-
expect(JSON.parse(op.value)).to.eql(triple)
622+
expect(JSON.parse(op.value)).to.eql({ extra: 'data' })
623623
})
624624
})
625625

@@ -642,17 +642,17 @@ describe('generateBatch', function () {
642642
db.close(done)
643643
})
644644
it('should generate a batch from a triple with length 3', function () {
645-
var triple = { subject: 'a', predicate: 'b', object: 'c' }
645+
var triple = { subject: 'a', predicate: 'b', object: 'c', other: 'stuff' }
646646
var ops = db._generateBatch(triple)
647647
expect(ops).to.have.property('length', 3)
648648
ops.forEach(function (op) {
649649
expect(op).to.have.property('type', 'put')
650-
expect(JSON.parse(op.value)).to.eql(triple)
650+
expect(JSON.parse(op.value)).to.eql({ other: 'stuff' })
651651
})
652652
})
653653

654654
it('should generate a batch of type', function () {
655-
var triple = { subject: 'a', predicate: 'b', object: 'c' }
655+
var triple = { subject: 'a', predicate: 'b', object: 'c', other: 'stuff' }
656656
var ops = db._generateBatch(triple, 'del')
657657
expect(ops).to.have.property('length', 3)
658658
ops.forEach(function (op) {

0 commit comments

Comments
 (0)