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

Function localViewCleanup

lib/index.js:9017–9079  ·  view source on GitHub ↗
(db)

Source from the content-addressed store, hash-verified

9015 }
9016
9017 async function localViewCleanup(db) {
9018 try {
9019 const metaDoc = await db.get('_local/' + localDocName);
9020 const docsToViews = new Map();
9021
9022 for (const fullViewName of Object.keys(metaDoc.views)) {
9023 const parts = parseViewName(fullViewName);
9024 const designDocName = '_design/' + parts[0];
9025 const viewName = parts[1];
9026 let views = docsToViews.get(designDocName);
9027 if (!views) {
9028 views = new Set();
9029 docsToViews.set(designDocName, views);
9030 }
9031 views.add(viewName);
9032 }
9033 const opts = {
9034 keys : mapToKeysArray(docsToViews),
9035 include_docs : true
9036 };
9037
9038 const res$$1 = await db.allDocs(opts);
9039 const viewsToStatus = {};
9040 for (const row of res$$1.rows) {
9041 const ddocName = row.key.substring(8); // cuts off '_design/'
9042 for (const viewName of docsToViews.get(row.key)) {
9043 let fullViewName = ddocName + '/' + viewName;
9044 /* istanbul ignore if */
9045 if (!metaDoc.views[fullViewName]) {
9046 // new format, without slashes, to support PouchDB 2.2.0
9047 // migration test in pouchdb's browser.migration.js verifies this
9048 fullViewName = viewName;
9049 }
9050 const viewDBNames = Object.keys(metaDoc.views[fullViewName]);
9051 // design doc deleted, or view function nonexistent
9052 const statusIsGood = row.doc && row.doc.views &&
9053 row.doc.views[viewName];
9054 for (const viewDBName of viewDBNames) {
9055 viewsToStatus[viewDBName] = viewsToStatus[viewDBName] || statusIsGood;
9056 }
9057 }
9058 }
9059
9060 const dbsToDelete = Object.keys(viewsToStatus)
9061 .filter(function (viewDBName) { return !viewsToStatus[viewDBName]; });
9062
9063 const destroyPromises = dbsToDelete.map(function (viewDBName) {
9064 return sequentialize(getQueue(viewDBName), function () {
9065 return new db.constructor(viewDBName, db.__opts).destroy();
9066 })();
9067 });
9068
9069 return Promise.all(destroyPromises).then(function () {
9070 return {ok: true};
9071 });
9072 } catch (err) {
9073 if (err.status === 404) {
9074 return {ok: true};

Callers 1

createAbstractMapReduceFunction · 0.70

Calls 7

parseViewNameFunction · 0.70
mapToKeysArrayFunction · 0.70
sequentializeFunction · 0.70
getQueueFunction · 0.70
getMethod · 0.45
addMethod · 0.45
destroyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…