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

Function createAbstractMapReduce

lib/index-browser.js:8144–9150  ·  view source on GitHub ↗

* Returns an "abstract" mapreduce object of the form: * * { * query: queryFun, * viewCleanup: viewCleanupFun * } * * Arguments are: * * localDoc: string * This is for the local doc that gets saved in order to track the * "dependent" DBs and clean them up for viewCleanup. I

(localDocName, mapper, reducer, ddocValidator)

Source from the content-addressed store, hash-verified

8142 * indexer is invalid.
8143 */
8144function createAbstractMapReduce(localDocName, mapper, reducer, ddocValidator) {
8145
8146 function tryMap(db, fun, doc) {
8147 // emit an event if there was an error thrown by a map function.
8148 // putting try/catches in a single function also avoids deoptimizations.
8149 try {
8150 fun(doc);
8151 } catch (e) {
8152 emitError(db, e, {fun, doc});
8153 }
8154 }
8155
8156 function tryReduce(db, fun, keys, values, rereduce) {
8157 // same as above, but returning the result or an error. there are two separate
8158 // functions to avoid extra memory allocations since the tryCode() case is used
8159 // for custom map functions (common) vs this function, which is only used for
8160 // custom reduce functions (rare)
8161 try {
8162 return {output : fun(keys, values, rereduce)};
8163 } catch (e) {
8164 emitError(db, e, {fun, keys, values, rereduce});
8165 return {error: e};
8166 }
8167 }
8168
8169 function sortByKeyThenValue(x, y) {
8170 const keyCompare = collate(x.key, y.key);
8171 return keyCompare !== 0 ? keyCompare : collate(x.value, y.value);
8172 }
8173
8174 function sliceResults(results, limit, skip) {
8175 skip = skip || 0;
8176 if (typeof limit === 'number') {
8177 return results.slice(skip, limit + skip);
8178 } else if (skip > 0) {
8179 return results.slice(skip);
8180 }
8181 return results;
8182 }
8183
8184 function rowToDocId(row) {
8185 const val = row.value;
8186 // Users can explicitly specify a joined doc _id, or it
8187 // defaults to the doc _id that emitted the key/value.
8188 const docId = (val && typeof val === 'object' && val._id) || row.id;
8189 return docId;
8190 }
8191
8192 function readAttachmentsAsBlobOrBuffer(res) {
8193 for (const row of res.rows) {
8194 const atts = row.doc && row.doc._attachments;
8195 if (!atts) {
8196 continue;
8197 }
8198 for (const filename of Object.keys(atts)) {
8199 const att = atts[filename];
8200 atts[filename].data = b64ToBluffer(att.data, att.content_type);
8201 }

Callers 1

index-browser.jsFile · 0.70

Calls 5

callbackifyFunction · 0.70
customViewCleanupFunction · 0.70
isRemoteFunction · 0.70
httpViewCleanupFunction · 0.70
localViewCleanupFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…