如何限制 PouchDB 修订或永久删除修订
How to limit PouchDB revisions or permanently delete revisions
我正在使用 PouchDB
和 websql
适配器或 cordova 应用程序(我正在使用 sqlite 插件)。
N.B。这个数据库完全是本地的,我不需要同步它。
对于我的特定应用程序(数据库用于跟踪 API 调用),我可以多次更新同一个文档。
即使我删除了文档并压缩了数据库,我的数据库仍然在增长。
我曾尝试在删除文档后进行压缩,尽管它有所不同 - 仍然保存修订存在的记录 - 所以我的数据库仍然无限增长。
如何阻止数据库无限增长?
删除(通过设置 doc._deleted = true
然后 db.put(doc)
)和压缩似乎不起作用。
查看下面的一条记录,尽管我删除了它并压缩了数据库,但它的所有修订仍在继续增长:
{
"id": "STATUS_TYPE_WEB_BROADCAST_RESULT_APICALL_5",
"deleted": true,
"rev_tree": [
{
"pos": 1,
"ids": [
"561567a6abccf9e25063be1cff906862",
{
"status": "missing"
},
[
[
"76a29a5ea586f54b86d9f7671fa0938a",
{
"status": "missing"
},
[
[
"00945a90f36790a6e25c3c8c99ecb008",
{
"status": "missing",
"deleted": true
},
[
[
"1844208b140a98fe83ccf547f3da1516",
{
"status": "missing"
},
[
[
"dd56c4b8dfae01cf3eabfad3ea21bf84",
{
"status": "missing"
},
[
[
"9152aac8de2c87c2265cc34ef1e992a9",
{
"status": "missing",
"deleted": true
},
[
[
"6ac6a3e5593250b2f6f3b9de5f2b80d0",
{
"status": "missing"
},
[
[
"1c400fcbabe3fe9ee6b923e99ab87b3e",
{
"status": "missing"
},
[
[
"6d3b88e73b6f880152f4e0418ab3a67d",
{
"status": "missing",
"deleted": true
},
[
[
"b2af3344fd9888653777e24bfd15dae4",
{
"status": "missing"
},
[
[
"d70cd32d571868ee2a49b14eb9ff3cf1",
{
"status": "missing"
},
[
[
"3ece08f0894f93859915812aba9d294b",
{
"status": "missing",
"deleted": true
},
[
[
"7f31761497f509e6e5b0815b659405dd",
{
"status": "missing"
},
[
[
"c3db1ae3c411389ac9e099c5739420af",
{
"status": "missing"
},
[
[
"a0c86c197187b210a4030742da03416c",
{
"status": "missing",
"deleted": true
},
[
[
"d89180025074fc48c28fbc785e034218",
{
"status": "missing"
},
[
[
"00eb69a55afea63ac30b9fa9038e3f1e",
{
"status": "missing"
},
[
[
"b8c051e94c65e485b2129464b0b4830b",
{
"status": "missing",
"deleted": true
},
[
[
"2832699d4da2bec534a129ade793bcb8",
{
"status": "missing"
},
[
[
"f8314cb28d7d7466b7e15ff7756f703a",
{
"status": "missing"
},
[
[
"398e27cf400f815c04eb5059900949d8",
{
"status": "missing",
"deleted": true
},
[
[
"747af489d66690927251e71ad4608500",
{
"status": "missing"
},
[
[
"4f2766536562894054c6220ef84fb782",
{
"status": "missing"
},
[
[
"536677ee9decf93b77d2d4b2a4243936",
{
"status": "missing",
"deleted": true
},
[
[
"82d9b89e3ac956f5bc64d27a32ba3d5b",
{
"status": "missing"
},
[
[
"23fe3cfd7bce5a6e0d279c708dc3565c",
{
"status": "missing"
},
[
[
"3c7f3d5b774f0549ca3c80700e84e074",
{
"status": "missing",
"deleted": true
},
[
[
"5b0db6e212bbf58e4d162389dc67800b",
{
"status": "missing"
},
[
[
"94b5b06de69d7b02bfa0800a4a895113",
{
"status": "missing"
},
[
[
"bb35cf47fa3da85eb2941c667c7ab40e",
{
"status": "missing",
"deleted": true
},
[
[
"432ea39039c355f9b1512c40b237ec38",
{
"status": "missing"
},
[
[
"f09f2f15dde4bd327f20c1beabc2ae13",
{
"status": "missing"
},
[
[
"b4a21b8562c085e0a2a91ca9ba5e6385",
{
"status": "available",
"deleted": true
},
[]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
}
],
"seq": 230
}
你试过自动压缩吗?
var db = new PouchDB('mydb', {auto_compaction: true});
db.put({_id: 'foo', version: 1}).then(function () {
return db.get('foo');
}).then(function (doc) {
doc.version = 2;
return db.put(doc);
}).then(function () {
// Revision 1 is already unavailable!
}).catch(function (err) {
// handle errors
});
我通过在 pouchDb 的 github:link to github issue.
上打开一个问题得到了答案
以下是 @daleyharvey 在 github 上的回答。如您所见,主要的事情是将 revs_limit: 1
添加到我的初始化中。这阻止了我的数据库无限制地增长。
新 PouchDB('name', {revs_limit: 1, auto_compaction: true})
应该做你想做的,revs_limit
是我们跟踪的修订数量(这是你看到的)压缩删除这些修订的内容
作为旁注,对于我的用例,我最终发现不需要使用 PouchDB 等高级数据库,最终 - 我需要普通的 WebSQL 或本地存储。
我正在使用 PouchDB
和 websql
适配器或 cordova 应用程序(我正在使用 sqlite 插件)。
N.B。这个数据库完全是本地的,我不需要同步它。
对于我的特定应用程序(数据库用于跟踪 API 调用),我可以多次更新同一个文档。
即使我删除了文档并压缩了数据库,我的数据库仍然在增长。
我曾尝试在删除文档后进行压缩,尽管它有所不同 - 仍然保存修订存在的记录 - 所以我的数据库仍然无限增长。
如何阻止数据库无限增长?
删除(通过设置 doc._deleted = true
然后 db.put(doc)
)和压缩似乎不起作用。
查看下面的一条记录,尽管我删除了它并压缩了数据库,但它的所有修订仍在继续增长:
{
"id": "STATUS_TYPE_WEB_BROADCAST_RESULT_APICALL_5",
"deleted": true,
"rev_tree": [
{
"pos": 1,
"ids": [
"561567a6abccf9e25063be1cff906862",
{
"status": "missing"
},
[
[
"76a29a5ea586f54b86d9f7671fa0938a",
{
"status": "missing"
},
[
[
"00945a90f36790a6e25c3c8c99ecb008",
{
"status": "missing",
"deleted": true
},
[
[
"1844208b140a98fe83ccf547f3da1516",
{
"status": "missing"
},
[
[
"dd56c4b8dfae01cf3eabfad3ea21bf84",
{
"status": "missing"
},
[
[
"9152aac8de2c87c2265cc34ef1e992a9",
{
"status": "missing",
"deleted": true
},
[
[
"6ac6a3e5593250b2f6f3b9de5f2b80d0",
{
"status": "missing"
},
[
[
"1c400fcbabe3fe9ee6b923e99ab87b3e",
{
"status": "missing"
},
[
[
"6d3b88e73b6f880152f4e0418ab3a67d",
{
"status": "missing",
"deleted": true
},
[
[
"b2af3344fd9888653777e24bfd15dae4",
{
"status": "missing"
},
[
[
"d70cd32d571868ee2a49b14eb9ff3cf1",
{
"status": "missing"
},
[
[
"3ece08f0894f93859915812aba9d294b",
{
"status": "missing",
"deleted": true
},
[
[
"7f31761497f509e6e5b0815b659405dd",
{
"status": "missing"
},
[
[
"c3db1ae3c411389ac9e099c5739420af",
{
"status": "missing"
},
[
[
"a0c86c197187b210a4030742da03416c",
{
"status": "missing",
"deleted": true
},
[
[
"d89180025074fc48c28fbc785e034218",
{
"status": "missing"
},
[
[
"00eb69a55afea63ac30b9fa9038e3f1e",
{
"status": "missing"
},
[
[
"b8c051e94c65e485b2129464b0b4830b",
{
"status": "missing",
"deleted": true
},
[
[
"2832699d4da2bec534a129ade793bcb8",
{
"status": "missing"
},
[
[
"f8314cb28d7d7466b7e15ff7756f703a",
{
"status": "missing"
},
[
[
"398e27cf400f815c04eb5059900949d8",
{
"status": "missing",
"deleted": true
},
[
[
"747af489d66690927251e71ad4608500",
{
"status": "missing"
},
[
[
"4f2766536562894054c6220ef84fb782",
{
"status": "missing"
},
[
[
"536677ee9decf93b77d2d4b2a4243936",
{
"status": "missing",
"deleted": true
},
[
[
"82d9b89e3ac956f5bc64d27a32ba3d5b",
{
"status": "missing"
},
[
[
"23fe3cfd7bce5a6e0d279c708dc3565c",
{
"status": "missing"
},
[
[
"3c7f3d5b774f0549ca3c80700e84e074",
{
"status": "missing",
"deleted": true
},
[
[
"5b0db6e212bbf58e4d162389dc67800b",
{
"status": "missing"
},
[
[
"94b5b06de69d7b02bfa0800a4a895113",
{
"status": "missing"
},
[
[
"bb35cf47fa3da85eb2941c667c7ab40e",
{
"status": "missing",
"deleted": true
},
[
[
"432ea39039c355f9b1512c40b237ec38",
{
"status": "missing"
},
[
[
"f09f2f15dde4bd327f20c1beabc2ae13",
{
"status": "missing"
},
[
[
"b4a21b8562c085e0a2a91ca9ba5e6385",
{
"status": "available",
"deleted": true
},
[]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
}
],
"seq": 230
}
你试过自动压缩吗?
var db = new PouchDB('mydb', {auto_compaction: true});
db.put({_id: 'foo', version: 1}).then(function () {
return db.get('foo');
}).then(function (doc) {
doc.version = 2;
return db.put(doc);
}).then(function () {
// Revision 1 is already unavailable!
}).catch(function (err) {
// handle errors
});
我通过在 pouchDb 的 github:link to github issue.
上打开一个问题得到了答案以下是 @daleyharvey 在 github 上的回答。如您所见,主要的事情是将 revs_limit: 1
添加到我的初始化中。这阻止了我的数据库无限制地增长。
新 PouchDB('name', {revs_limit: 1, auto_compaction: true})
应该做你想做的,revs_limit
是我们跟踪的修订数量(这是你看到的)压缩删除这些修订的内容
作为旁注,对于我的用例,我最终发现不需要使用 PouchDB 等高级数据库,最终 - 我需要普通的 WebSQL 或本地存储。