about summary refs log tree commit diff
path: root/src/Main.hs
diff options
context:
space:
mode:
authorVincent Ambo <viam@humac.com>2012-03-03T02·47+0100
committerVincent Ambo <viam@humac.com>2012-03-03T02·47+0100
commit65a5443e2d3f523dc3a61e6cdf2a9a588e6ac368 (patch)
treeab9bb823bbd8b0304ce3670be9c6d9b73752374b /src/Main.hs
parent9e4b35613cf2f11318a1dba2fa47861872d7a8f2 (diff)
* getMonthCount now takes a BlogLang, as is obviously required
Diffstat (limited to 'src/Main.hs')
-rw-r--r--src/Main.hs12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/Main.hs b/src/Main.hs
index fb1cf07a5d39..3c4537597611 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -105,9 +105,9 @@ stripResult :: Result a -> a
 stripResult (Ok z) = z
 stripResult (Error s) = error $ "JSON error: " ++ s
 
-getMonthCount :: Int -> Int -> ServerPart Int
-getMonthCount y m  = do
-    count <- queryDB "countDE" $ makeQuery startkey endkey
+getMonthCount :: BlogLang -> Int -> Int -> ServerPart Int
+getMonthCount lang y m  = do
+    count <- queryDB (view lang) $ makeQuery startkey endkey
     return . stripCount $ map (stripResult . fromJSON . snd) count
   where
     startkey = JSArray [toJSON ("count" :: String), toJSON y, toJSON m]
@@ -115,13 +115,15 @@ getMonthCount y m  = do
     stripCount :: [Int] -> Int
     stripCount [x] = x
     stripCount [] = 0
+    view DE = "countDE"
+    view EN = "countEN"
 
 
 -- CouchDB View Setup
 latestDEView = "function(doc){ if(doc.lang == 'DE'){ emit([doc.year, doc.month, doc.day, doc._id], doc); } }"
 latestENView = "function(doc){ if(doc.lang == 'EN'){ emit([doc.year, doc.month, doc.day, doc._id], doc); } }"
-countDEView  = "function(doc){ if(doc.lang == 'DE'){ emit([doc.year, doc.month, doc.day, doc._id], 1); } }"
-countENView  = "function(doc){ if(doc.lang == 'EN'){ emit([doc.year, doc.month, doc.day, doc._id], 1); } }"
+countDEView  = "function(doc){ if(doc.lang == 'DE'){ emit(['count', doc.year, doc.month, doc.day, doc._id], 1); } }"
+countENView  = "function(doc){ if(doc.lang == 'EN'){ emit(['count', doc.year, doc.month, doc.day, doc._id], 1); } }"
 countReduce  = "function(keys, values, rereduce) { return sum(values); }"
 
 latestDE = ViewMap "latestDE" latestDEView