Comparing version 3.1.0 to 3.1.1
const after = require('after') | ||
, xtend = require('xtend') | ||
, encoding = require('./encoding') | ||
, Lock = require('lock') | ||
@@ -114,20 +115,23 @@ function prefixKey (db, key) { | ||
ttloff(db, keys, function () { | ||
keys.forEach(function (key) { | ||
batch.push({ type: 'put', key: expiryKey(db, exp, key), value: encode(key) }) | ||
batch.push({ type: 'put', key: prefixKey(db, key), value: encode(exp) }) | ||
}) | ||
db._ttl._lock(keys, function (release) { | ||
callback = release(callback || function () {}) | ||
ttloff(db, keys, function () { | ||
keys.forEach(function (key) { | ||
batch.push({ type: 'put', key: expiryKey(db, exp, key), value: encode(key) }) | ||
batch.push({ type: 'put', key: prefixKey(db, key), value: encode(exp) }) | ||
}) | ||
if (!batch.length) | ||
return callback && callback() | ||
if (!batch.length) | ||
return callback() | ||
batchFn( | ||
batch | ||
, { keyEncoding: 'binary', valueEncoding: 'binary' } | ||
, function (err) { | ||
if (err) | ||
db.emit('error', err) | ||
callback && callback() | ||
} | ||
) | ||
batchFn( | ||
batch | ||
, { keyEncoding: 'binary', valueEncoding: 'binary' } | ||
, function (err) { | ||
if (err) | ||
db.emit('error', err) | ||
callback() | ||
} | ||
) | ||
}) | ||
}) | ||
@@ -298,2 +302,3 @@ } | ||
, _expiryNs : _prefixNs.concat(options.expiryNamespace) | ||
, _lock : new Lock() | ||
} | ||
@@ -300,0 +305,0 @@ |
@@ -11,3 +11,3 @@ { | ||
], | ||
"version": "3.1.0", | ||
"version": "3.1.1", | ||
"homepage": "https://github.com/level/level-ttl", | ||
@@ -32,2 +32,3 @@ "authors": [ | ||
"list-stream": ">=1.0.0 <1.1.0-0", | ||
"lock": "~0.1.2", | ||
"xtend": ">=4.0.0 <4.1.0-0" | ||
@@ -39,5 +40,5 @@ }, | ||
"level-sublevel": "^6.4.6", | ||
"ltest": "2.0.0", | ||
"ltest": "^2.1.1", | ||
"slump": "^2.0.0", | ||
"tape": ">=2.14.0 <2.15.0-0", | ||
"tape": "^4.3.0", | ||
"bytewise": ">=0.8" | ||
@@ -44,0 +45,0 @@ }, |
22
test.js
@@ -763,1 +763,23 @@ const tape = require('tape') | ||
}) | ||
test('prolong entry with PUT should not duplicate the TTL key', function (t, db, createReadStream) { | ||
var retest = function (delay, cb) { | ||
setTimeout(function () { | ||
db.put('bar', 'barvalue', { ttl: 20 }) | ||
verifyIn(50, createReadStream, t, function (arr) { | ||
var count = arr.filter(function (kv) { | ||
return /!ttl!x!\d{13}!bar/.exec(kv.key); | ||
}).length | ||
t.ok(count <= 1, 'contains one or zero TTL entry') | ||
cb && cb() | ||
}) | ||
}, delay) | ||
} | ||
, i | ||
db.put('foo', 'foovalue') | ||
for (i = 0; i < 50; i++) | ||
retest(i) | ||
retest(50, t.end.bind(t)) | ||
}, { checkFrequency: 5 }) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
44852
987
4
+ Addedlock@~0.1.2
+ Addedlock@0.1.4(transitive)