[
https://issues.apache.org/jira/browse/COUCHDB-1961?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13846467#comment-13846467
]
Alexander Shorin commented on COUCHDB-1961:
-------------------------------------------
Here is modified docUtil:
{code}
function env() {
var _metaCreate = function() {
return({
a: 'create',
b: 'bbbb'
});
};
var _metaModify = function() {
return({
a: 'modify',
b: 'bbbb'
});
};
return {
metaCreate: _metaCreate,
metaModify: _metaModify
};
}
exports.docUtil = env();
{code}
and update function codes:
{code}
function(doc, req) {
var docUtil = require('views/lib/docUtil').docUtil;
if(!doc) {
doc = {};
}
doc._id = 'two';
doc.meta = docUtil.metaCreate();
return([doc, JSON.stringify(doc, undefined, 2)]);
}
{code}
Changes are trivial, but they makes things clear and there is no issues with
cache. Explicit is better than implicit (;
> CouchDB Module Cache Misbehaving
> --------------------------------
>
> Key: COUCHDB-1961
> URL: https://issues.apache.org/jira/browse/COUCHDB-1961
> Project: CouchDB
> Issue Type: Bug
> Components: JavaScript View Server
> Affects Versions: 1.3.1, 1.4.0, 1.5.0
> Reporter: James Dingwall
>
> The module cache is breaking update functions which share a common module via
> require(). Disabling the caching by adding || true in main.js at line 1174
> (CouchDB 1.5.0) resolves the problem. With this disabled then both curl
> commands in the example pass.
> This code was introduced in https://issues.apache.org/jira/browse/COUCHDB-1075
> Here is a complete test case design document which demonstrates the problem.
> {
> "_id": "_design/ptest",
> "updates": {
> "two": "function(doc, req)
> {\n\trequire('views/lib/docUtil');\n\n\tif(!doc) {\n\t\tdoc =
> {};\n\t}\n\n\tdoc._id = 'two';\n\n\tdoc.meta =
> docUtil.metaCreate();\n\n\treturn([doc, JSON.stringify(doc, undefined,
> 2)]);\n}",
> "one": "function(doc, req)
> {\n\trequire('views/lib/docUtil');\n\n\tif(!doc) {\n\t\tdoc =
> {};\n\t}\n\n\tdoc._id = 'one';\n\n\tdoc.meta =
> docUtil.metaCreate();\n\n\treturn([doc, JSON.stringify(doc, undefined,
> 2)]);\n}"
> },
> "language": "javascript",
> "views": {
> "lib": {
> "docUtil": "(function(global) {\n\nvar _metaCreate = function()
> {\n\treturn({\n\t\ta: 'create',\n\t\tb: 'bbbb'\n\t});\n};\n\nvar _metaModify
> = function() {\n\treturn({\n\t\ta: 'modify',\n\t\tb:
> 'bbbb'\n\t});\n};\n\nglobal.docUtil = {\n\tmetaCreate:
> _metaCreate,\n\tmetaModify: _metaModify\n};\n\nlog('require
> docUtil');\n\n})(exports.docUtil = this)"
> }
> },
> "type": "design/ptest"
> }
> Call the update functions like:
> curl -X POST http://couchdb:5984/zydev/_design/ptest/_update/one - creates a
> document
> curl -X POST http://couchdb:5984/zydev/_design/ptest/_update/two - fails
--
This message was sent by Atlassian JIRA
(v6.1.4#6159)