0

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

目的是清理在很长一段时间内有许多修订的文档的数据库

我需要帮助编写一个函数,该函数发出一个 FB 命令来删除比“ns”快照早“nd”天的所有修订。

我不确定此命令的 Firebase 语法以及如何正确访问相关的 Firebase 密钥。

任何帮助将不胜感激

谢谢!

4

1 回答 1

0

最终解决了这个问题

公关:https ://github.com/firebase/firepad/pull/264

代码:

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));
                }
            });
        }
    });
};
于 2016-10-08T00:24:13.953 回答