当前位置 : 主页 > 手机开发 > cordova >

database – 如何限制PouchDB修订或永久删除修订

来源:互联网 收集:自由互联 发布时间:2021-06-10
我正在使用带有websql适配器的PouchDB或一个cordova应用程序(我正在使用sqlite插件). 注:这个数据库是完全本地的,我不需要它同步. 对于我的特定应用程序(数据库用于跟踪API调用),我可以多
我正在使用带有websql适配器的PouchDB或一个cordova应用程序(我正在使用sqlite插件).

注:这个数据库是完全本地的,我不需要它同步.

对于我的特定应用程序(数据库用于跟踪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
}
我通过在pouchDb的github: link to github issue上打开一个问题得到了答案.

以下是github上@daleyharvey的答案.正如您所看到的,主要的是在我的初始化中添加revs_limit:1.这阻止了我的数据库不受限制地增长.

新的PouchDB(‘name’,{revs_limit:1,auto_compaction:true})应该做你想要的,revs_limit是我们跟踪的修订数量(这是你看到的)压缩删除那些修订的内容

就像一个侧面说明,对于我的用例,我最终发现在最终端不需要使用PouchDB等高级数据库 – 我需要普通的WebSQL或本地存储.

网友评论