diff --git a/src/main/resources/couchdb/answer.design.js b/src/main/resources/couchdb/Answer.design.js similarity index 72% rename from src/main/resources/couchdb/answer.design.js rename to src/main/resources/couchdb/Answer.design.js index a79ac0a403f0d1c97e5aa31faea5d8387333bf37..44d0a92f3b4ecf99a9bcfb878668bb2421f19847 100644 --- a/src/main/resources/couchdb/answer.design.js +++ b/src/main/resources/couchdb/Answer.design.js @@ -1,59 +1,58 @@ var designDoc = { - "_id": "_design/answer", + "_id": "_design/Answer", "language": "javascript", "views": { - "doc_by_questionid_user_piround": { + "by_questionid": { "map": function (doc) { if (doc.type === "skill_question_answer") { - emit([doc.questionId, doc.user, doc.piRound], doc); + emit(doc.questionId, {_rev: doc._rev}); } } }, - "doc_by_questionid_timestamp": { + "by_questionid_piround_text_subject": { "map": function (doc) { if (doc.type === "skill_question_answer") { - emit([doc.questionId, doc.timestamp], doc); + emit([doc.questionId, doc.piRound, doc.abstention, doc.answerText, doc.answerSubject, doc.successfulFreeTextAnswer], {_rev: doc._rev}); } - } + }, + "reduce": "_count" }, - "doc_by_user_sessionid": { + "by_questionid_timestamp": { "map": function (doc) { if (doc.type === "skill_question_answer") { - emit([doc.user, doc.sessionId], doc); + emit([doc.questionId, doc.timestamp], {_rev: doc._rev}); } } }, - "by_questionid": { + "by_questionid_user_piround": { "map": function (doc) { if (doc.type === "skill_question_answer") { - emit(doc.questionId, null); + emit([doc.questionId, doc.user, doc.piRound], {_rev: doc._rev}); } } }, - "by_questionid_piround_text_subject": { + "by_sessionid": { "map": function (doc) { if (doc.type === "skill_question_answer") { - emit([doc.questionId, doc.piRound, doc.abstention, doc.answerText, doc.answerSubject, doc.successfulFreeTextAnswer], null); + emit(doc.sessionId, {_rev: doc._rev}); } }, "reduce": "_count" }, - "by_sessionid": { - /* Redundant view but kept for now to allow simpler queries. */ + "by_sessionid_variant": { "map": function (doc) { if (doc.type === "skill_question_answer") { - emit(doc.sessionId, null); + emit([doc.sessionId, doc.questionVariant], {_rev: doc._rev}); } }, "reduce": "_count" }, - "by_sessionid_variant": { + "by_user_sessionid": { "map": function (doc) { if (doc.type === "skill_question_answer") { - emit([doc.sessionId, doc.questionVariant], null); + emit([doc.user, doc.sessionId], {_rev: doc._rev}); } - }, - "reduce": "_count" + } }, "questionid_by_user_sessionid_variant": { "map": function (doc) { diff --git a/src/main/resources/couchdb/comment.design.js b/src/main/resources/couchdb/Comment.design.js similarity index 61% rename from src/main/resources/couchdb/comment.design.js rename to src/main/resources/couchdb/Comment.design.js index 23936b94eb52f3eddd55b416c2dcd19189c26e18..c407a2eb551f8c45f8f87c8efcdc69443d1affc1 100644 --- a/src/main/resources/couchdb/comment.design.js +++ b/src/main/resources/couchdb/Comment.design.js @@ -1,45 +1,44 @@ var designDoc = { - "_id": "_design/comment", + "_id": "_design/Comment", "language": "javascript", "views": { - "doc_by_sessionid_creator_timestamp": { + "by_sessionid": { "map": function (doc) { if (doc.type === "interposed_question") { - emit([doc.sessionId, doc.creator, doc.timestamp], doc); + emit(doc.sessionId, {_rev: doc._rev}); } - } + }, + "reduce": "_count" }, - "doc_by_sessionid_timestamp": { + "by_sessionid_creator_read": { "map": function (doc) { if (doc.type === "interposed_question") { - emit([doc.sessionId, doc.timestamp], doc); + emit([doc.sessionId, doc.creator, doc.read], {_rev: doc._rev}) } - } + }, + "reduce": "_count" }, - "by_sessionid": { - /* Redundant view but kept for now to allow simpler queries. */ + "by_sessionid_creator_timestamp": { "map": function (doc) { if (doc.type === "interposed_question") { - emit(doc.sessionId, null); + emit([doc.sessionId, doc.creator, doc.timestamp], {_rev: doc._rev}); } - }, - "reduce": "_count" + } }, "by_sessionid_read": { "map": function (doc) { if (doc.type === "interposed_question") { - emit([doc.sessionId, doc.read], null); + emit([doc.sessionId, doc.read], {_rev: doc._rev}); } }, "reduce": "_count" }, - "by_sessionid_creator_read": { + "by_sessionid_timestamp": { "map": function (doc) { if (doc.type === "interposed_question") { - emit([doc.sessionId, doc.creator, doc.read], null); + emit([doc.sessionId, doc.timestamp], {_rev: doc._rev}); } - }, - "reduce": "_count" + } } } }; diff --git a/src/main/resources/couchdb/Content.design.js b/src/main/resources/couchdb/Content.design.js new file mode 100644 index 0000000000000000000000000000000000000000..cb3f2f98208cb83b87d7d5b1183f43c969629c1f --- /dev/null +++ b/src/main/resources/couchdb/Content.design.js @@ -0,0 +1,22 @@ +var designDoc = { + "_id": "_design/Content", + "language": "javascript", + "views": { + "by_sessionid": { + "map": function (doc) { + if (doc.type === "skill_question") { + emit(doc.sessionId, {_rev: doc._rev}); + } + }, + "reduce": "_count" + }, + "by_sessionid_variant_active": { + "map": function (doc) { + if (doc.type === "skill_question") { + emit([doc.sessionId, doc.questionVariant, doc.active, doc.subject, doc.text.substr(0, 16)], {_rev: doc._rev}); + } + }, + "reduce": "_count" + } + } +}; diff --git a/src/main/resources/couchdb/user.design.js b/src/main/resources/couchdb/DbUser.design.js similarity index 69% rename from src/main/resources/couchdb/user.design.js rename to src/main/resources/couchdb/DbUser.design.js index 9299516f89a56f92017224eb5416e16ab3b9cba8..aa63058d15eb951257a7e076ba2f8cb99a25bb15 100644 --- a/src/main/resources/couchdb/user.design.js +++ b/src/main/resources/couchdb/DbUser.design.js @@ -1,20 +1,18 @@ var designDoc = { - "_id": "_design/user", + "_id": "_design/DbUser", "language": "javascript", "views": { - "doc_by_username": { - "map": function (doc) { - if (doc.type === "userdetails") { - emit(doc.username, doc); - } - } - }, "by_creation_for_inactive": { "map": function (doc) { if (doc.type === "userdetails" && doc.activationKey) { emit(doc.creation, {_rev: doc._rev}); } } + }, + "by_username": { + "map": function (doc) { + if (doc.type === "userdetails") emit(doc.username, {_rev: doc._rev}); + } } } }; diff --git a/src/main/resources/couchdb/logged_in.design.js b/src/main/resources/couchdb/LoggedIn.design.js similarity index 94% rename from src/main/resources/couchdb/logged_in.design.js rename to src/main/resources/couchdb/LoggedIn.design.js index 1b196b4f5aecb0e8516d638de58da599941c5913..aadec2d1e364f8ef9b15defa43c75dae29f4ba68 100644 --- a/src/main/resources/couchdb/logged_in.design.js +++ b/src/main/resources/couchdb/LoggedIn.design.js @@ -1,14 +1,7 @@ var designDoc = { - "_id": "_design/logged_in", + "_id": "_design/LoggedIn", "language": "javascript", "views": { - "visited_sessions_by_user": { - "map": function (doc) { - if (doc.type === "logged_in") { - emit(doc.user, doc.visitedSessions); - } - } - }, "all": { "map": function (doc) { if (doc.type === "logged_in"){ @@ -22,6 +15,13 @@ var designDoc = { emit(doc.timestamp || 0, {_rev: doc._rev}); } } + }, + "visited_sessions_by_user": { + "map": function (doc) { + if (doc.type === "logged_in") { + emit(doc.user, doc.visitedSessions); + } + } } } }; diff --git a/src/main/resources/couchdb/motd.design.js b/src/main/resources/couchdb/Motd.design.js similarity index 63% rename from src/main/resources/couchdb/motd.design.js rename to src/main/resources/couchdb/Motd.design.js index 33b111ee3f0765829ca9b4731cbeec47f1efbb8f..8e932510dc5ee7fddcae328058b636d1ae7ca2ac 100644 --- a/src/main/resources/couchdb/motd.design.js +++ b/src/main/resources/couchdb/Motd.design.js @@ -1,25 +1,25 @@ var designDoc = { - "_id": "_design/motd", + "_id": "_design/Motd", "language": "javascript", "views": { - "doc_by_sessionkey": { + "by_audience_for_global": { "map": function (doc) { - if (doc.type === "motd" && doc.audience === "session") { - emit(doc.sessionkey, doc); + if (doc.type === "motd" && doc.audience !== "session") { + emit(doc.audience, {_rev: doc._rev}); } } }, - "doc_by_audience_for_global": { + "by_motdkey": { "map": function (doc) { - if (doc.type === "motd" && doc.audience !== "session") { - emit(doc.audience, doc); + if (doc.type === "motd") { + emit(doc.motdkey, {_rev: doc._rev}); } } }, - "by_motdkey": { + "by_sessionkey": { "map": function (doc) { - if (doc.type === "motd") { - emit(doc.motdkey, doc); + if (doc.type === "motd" && doc.audience === "session") { + emit(doc.sessionkey, {_rev: doc._rev}); } } } diff --git a/src/main/resources/couchdb/motdlist.design.js b/src/main/resources/couchdb/MotdList.design.js similarity index 87% rename from src/main/resources/couchdb/motdlist.design.js rename to src/main/resources/couchdb/MotdList.design.js index 37712e4ea35821de5b9b50d4a2e7b9e703589890..e7ddbe7621d93c89cb4b5ea2784369756452afe6 100644 --- a/src/main/resources/couchdb/motdlist.design.js +++ b/src/main/resources/couchdb/MotdList.design.js @@ -1,5 +1,5 @@ var designDoc = { - "_id": "_design/motdlist", + "_id": "_design/MotdList", "language": "javascript", "views": { "doc_by_username": { diff --git a/src/main/resources/couchdb/session.design.js b/src/main/resources/couchdb/Session.design.js similarity index 76% rename from src/main/resources/couchdb/session.design.js rename to src/main/resources/couchdb/Session.design.js index b8b1346b0a026b32d79c18be68ed55602b1a0357..790e3af6afe0829abf1c2d177a6baa94acb2d390 100644 --- a/src/main/resources/couchdb/session.design.js +++ b/src/main/resources/couchdb/Session.design.js @@ -1,18 +1,25 @@ var designDoc = { - "_id": "_design/session", + "_id": "_design/Session", "language": "javascript", "views": { "by_courseid": { "map": function (doc) { - if (doc.type === "session" && doc.courseId && doc.sessionType !== "public_pool") { - emit(doc.courseId, null); + if (doc.type === "session" && doc.courseId && doc.sessionType !== "public_pool") { + emit(doc.courseId, {_rev: doc._rev}); } } }, "by_keyword": { "map": function (doc) { if (doc.type === "session") { - emit(doc.keyword, null); + emit(doc.keyword, {_rev: doc._rev}); + } + } + }, + "by_lastactivity_for_guests": { + "map": function (doc) { + if (doc.type === "session" && doc.sessionType !== "public_pool" && doc.creator.indexOf("Guest") === 0) { + emit(doc.lastOwnerActivity || doc.creationTime, {_rev: doc._rev}); } } }, @@ -29,9 +36,9 @@ var designDoc = { } } }, - "partial_by_ppsubject_name_for_publicpool": { + "partial_by_subject_name_for_publicpool": { "map": function (doc) { - if (doc.type === "session" && doc.sessionType === "public_pool") { + if (doc.type === "session" && doc.sessiontype === "public_pool") { emit([doc.ppSubject, doc.name], { ppSubject: doc.ppSubject, name: doc.name, @@ -40,13 +47,6 @@ var designDoc = { }); } } - }, - "by_lastactivity_for_guests": { - "map": function (doc) { - if (doc.type === "session" && doc.sessionType !== "public_pool" && doc.creator.indexOf("Guest") === 0) { - emit(doc.lastOwnerActivity || doc.creationTime, {_rev: doc._rev}); - } - } } } }; diff --git a/src/main/resources/couchdb/content.design.js b/src/main/resources/couchdb/content.design.js deleted file mode 100644 index 74518a473fed5b92a06d9059ccaccad10f097e6d..0000000000000000000000000000000000000000 --- a/src/main/resources/couchdb/content.design.js +++ /dev/null @@ -1,31 +0,0 @@ -var designDoc = { - "_id": "_design/content", - "language": "javascript", - "views": { - "doc_by_sessionid_variant_active": { - "map": function (doc) { - if (doc.type === "skill_question") { - emit([doc.sessionId, doc.questionVariant, doc.active, doc.subject, doc.text.substr(0, 16)], doc); - } - }, - "reduce": "_count" - }, - "by_sessionid": { - /* Redundant view but kept for now to allow simpler queries. */ - "map": function (doc) { - if (doc.type === "skill_question") { - emit(doc.sessionId, null); - } - }, - "reduce": "_count" - }, - "by_sessionid_variant_active": { - "map": function (doc) { - if (doc.type === "skill_question") { - emit([doc.sessionId, doc.questionVariant, doc.active, doc.subject, doc.text.substr(0, 16)], null); - } - }, - "reduce": "_count" - } - } -};