首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >FirePad -删除所有比某个快照早几天的修订。

FirePad -删除所有比某个快照早几天的修订。
EN

Stack Overflow用户
提问于 2016-10-07 03:34:36
回答 1查看 298关注 0票数 0

这是从这里的一个旧线程继续https://groups.google.com/forum/#!topic/firepad-io/73dKYaUwTn4)

其目的是清理数据库中的文档,这些文档在很长一段时间内有许多修改。

我需要帮助编写一个函数,发出一个FB命令来删除所有比'ns‘快照更早的修订。

我不确定此命令的Firebase语法以及如何正确访问相关的防火墙键。

如有任何帮助,将不胜感激。

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-10-08 00:24:13

最终解决了这个问题

PR:https://github.com/firebase/firepad/pull/264

代码:

代码语言:javascript
复制
FirebaseAdapter.prototype.deleteOldRevisions_ = function(query) {
    var self=this;
    query.once('value', function(s) {
        if (typeof s.val() === 'undefined' || s.val() === null || !s.hasChildren()) return;
        s.forEach(function(rev) { 
            utils.log('removing old revision: '+rev.key);
            rev.ref.remove();
        });
        setTimeout(function() { self.deleteOldRevisions_(query); }, 100); // delete the next one
    });
}

FirebaseAdapter.prototype.monitorHistory_ = function() {
    var self = this;
    // Get the latest checkpoint as a starting point so we don't have to re-play entire history.
    self.ref_.child('checkpoint').once('value', function(s) {
        //utils.log(new Date().toISOString() + ': got checkpoint');
        if (self.zombie_) { return; } // just in case we were cleaned up before we got the checkpoint data.
        var revisionId = s.child('id').val(),  op = s.child('o').val(), author = s.child('a').val();
        if (op !== null && revisionId !== null && author !== null &&
            op !== undefined && revisionId !== undefined && author !== undefined) {
            self.pendingReceivedRevisions_[revisionId] = { o: op, a: author };
            self.checkpointRevision_ = revisionFromId(revisionId);
            self.monitorHistoryStartingAt_(self.checkpointRevision_ + 1);
        } else {
            self.checkpointRevision_ = 0;
            self.monitorHistoryStartingAt_(self.checkpointRevision_);
        }

        // delete revisions older than one week before last checkpoint
        if (revisionId) {
            var historyRef=self.ref_.child('history');
            historyRef.child(revisionId+'/t').once('value', function(s) {
                if (typeof s.val() !== 'undefined' && s.val() !== null) {
                    var weekBefore=s.val()-(24*60*60*1000*7);
                    //utils.log('checkpoint revision: '+self.checkpointRevision_);
                    //utils.log('checkpoint time: ' + new Date(s.val()));
                    //utils.log('remove before: ' + new Date(weekBefore));
                    self.deleteOldRevisions_(historyRef.orderByChild('t').endAt(weekBefore));
                }
            });
        }
    });
};
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39908947

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档