MCPcopy Index your code
hub / github.com/apache/pouchdb / compactRevs

Function compactRevs

lib/index-browser.js:4856–4915  ·  view source on GitHub ↗
(revs, docId, txn)

Source from the content-addressed store, hash-verified

4854}
4855
4856function compactRevs(revs, docId, txn) {
4857
4858 var possiblyOrphanedDigests = [];
4859 var seqStore = txn.objectStore(BY_SEQ_STORE);
4860 var attStore = txn.objectStore(ATTACH_STORE);
4861 var attAndSeqStore = txn.objectStore(ATTACH_AND_SEQ_STORE);
4862 var count = revs.length;
4863
4864 function checkDone() {
4865 count--;
4866 if (!count) { // done processing all revs
4867 deleteOrphanedAttachments();
4868 }
4869 }
4870
4871 function deleteOrphanedAttachments() {
4872 if (!possiblyOrphanedDigests.length) {
4873 return;
4874 }
4875 possiblyOrphanedDigests.forEach(function (digest) {
4876 var countReq = attAndSeqStore.index('digestSeq').count(
4877 IDBKeyRange.bound(
4878 digest + '::', digest + '::\uffff', false, false));
4879 countReq.onsuccess = function (e) {
4880 var count = e.target.result;
4881 if (!count) {
4882 // orphaned
4883 attStore.delete(digest);
4884 }
4885 };
4886 });
4887 }
4888
4889 revs.forEach(function (rev$$1) {
4890 var index = seqStore.index('_doc_id_rev');
4891 var key = docId + "::" + rev$$1;
4892 index.getKey(key).onsuccess = function (e) {
4893 var seq = e.target.result;
4894 if (typeof seq !== 'number') {
4895 return checkDone();
4896 }
4897 seqStore.delete(seq);
4898
4899 var cursor = attAndSeqStore.index('seq')
4900 .openCursor(IDBKeyRange.only(seq));
4901
4902 cursor.onsuccess = function (event) {
4903 var cursor = event.target.result;
4904 if (cursor) {
4905 var digest = cursor.value.digestSeq.split('::')[0];
4906 possiblyOrphanedDigests.push(digest);
4907 attAndSeqStore.delete(cursor.primaryKey);
4908 cursor.continue();
4909 } else { // done
4910 checkDone();
4911 }
4912 };
4913 };

Callers 2

afterPutDocFunction · 0.70
initFunction · 0.70

Calls 1

checkDoneFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…