Using couchdb to build a EMAIL messaging solution with threaded inline replies
Couchdb based Messaging system
The goal is to build an anonymous inbox with inline threaded replies and count of number of items in the inbox and sent. It works well, the only part that is hard is that the views are pretty slow the first time they are constructed
Schema
subject =
read =
fromread =
toread =
msg =
background =
type =
reply =
fromuid =
replycount =
touid =
created =
time =
date =
Permanent view for inbox:
function(d){ if(d.type != 'reply'){ emit(d.touid, d); if(d.touid != d.fromuid){ if (d.replycount>0) emit(d.fromuid, d); } } }
Count of number of messages in USER inbox
map:function(d){
if(d.type != 'reply'){
emit(d.touid, 1);
if(d.touid != d.fromuid){
if (d.replycount>0)
emit(d.fromuid, 1);
}
}
}
reduce:function(keys, values) { return sum(values)}
Count of Sent items
map:function(doc) { emit(doc.fromuid, 1) }
reduce:function(keys, values) { return sum(values)}
View to get replies
map:function(d) { if (d.type=="reply" ) emit(d.reply,d); }
Usage from python
inbox_messages =
2 comments:
"the views are pretty slow the first time they are constructed"
Could you give more details ?
How many documents did you have when you first queried the views ?
Did the count of messages was the most expensive ?
Thanks.
Is the code available?
Post a Comment