Permalink
Browse files

Drop garbage from common views quickly.

This helps to avoid replicating garbage.
  • Loading branch information...
1 parent b85ace8 commit 27606bc7d8b9727386ee4bfb5f8960fcb18e5bb3 @dustin dustin committed Nov 23, 2012
Showing with 15 additions and 4 deletions.
  1. +15 −4 database.go
View
@@ -20,13 +20,13 @@ type viewMarker struct {
}
const ddocKey = "/@ddocVersion"
-const ddocVersion = 1
+const ddocVersion = 2
const designDoc = `
{
"spatialInfos": [],
"viewInfos": [
{
- "map": "function (doc, meta) {\n if (doc.type === \"file\") {\n var toEmit = {};\n toEmit[doc.oid] = meta.id;\n if (doc.older) {\n for (var i = 0; i < doc.older.length; i++) {\n toEmit[doc.older[i].oid] = meta.id;\n }\n }\n for (var k in toEmit) {\n emit([k, \"file\", meta.id], null);\n }\n } else if (doc.type === \"blob\") {\n for (var node in doc.nodes) {\n emit([doc.oid, \"blob\", node], null);\n }\n }\n}",
+ "map": "function (doc, meta) {\n if (doc.type === \"file\") {\n var toEmit = {};\n toEmit[doc.oid] = meta.id;\n if (doc.older) {\n for (var i = 0; i < doc.older.length; i++) {\n toEmit[doc.older[i].oid] = meta.id;\n }\n }\n for (var k in toEmit) {\n emit([k, \"file\", meta.id], null);\n }\n } else if (doc.type === \"blob\") {\n var replicas=0;\n for (var node in doc.nodes) {\n replicas++;\n emit([doc.oid, \"blob\", node], null);\n }\n if (replicas === 0) {\n emit([doc.oid, \"blob\", \"\"], null);\n }\n }\n}",
"name": "file_blobs",
"removeLink": "#removeView=cbfs%2F_design%252Fdev_cbfs%2F_view%2Ffile_blobs",
"viewLink": "#showView=cbfs%2F_design%252Fdev_cbfs%2F_view%2Ffile_blobs"
@@ -39,6 +39,13 @@ const designDoc = `
"viewLink": "#showView=cbfs%2F_design%252Fdev_cbfs%2F_view%2Ffile_browse"
},
{
+ "map": "function (doc, meta) {\n if (doc.type === 'blob') {\n emit(doc.garbage ? 'garbage' : 'live', doc.length);\n }\n}",
+ "name": "garbage",
+ "reduce": "_stats",
+ "removeLink": "#removeView=cbfs%2F_design%252Fdev_cbfs%2F_view%2Fgarbage",
+ "viewLink": "#showView=cbfs%2F_design%252Fdev_cbfs%2F_view%2Fgarbage"
+ },
+ {
"map": "function (doc, meta) {\n if (doc.type === \"blob\") {\n for (var n in doc.nodes) {\n emit(n, null);\n }\n }\n}",
"name": "node_blobs",
"reduce": "_count",
@@ -53,7 +60,7 @@ const designDoc = `
"viewLink": "#showView=cbfs%2F_design%252Fdev_cbfs%2F_view%2Fnode_size"
},
{
- "map": "function (doc, meta) {\n if (doc.type === \"blob\") {\n var nreps = 0;\n for (var x in doc.nodes) {\n nreps++;\n }\n emit(nreps, null);\n }\n}",
+ "map": "function (doc, meta) {\n if (doc.type === \"blob\" && !doc.garbage) {\n var nreps = 0;\n for (var x in doc.nodes) {\n nreps++;\n }\n emit(nreps, null);\n }\n}",
"name": "repcounts",
"reduce": "_count",
"removeLink": "#removeView=cbfs%2F_design%252Fdev_cbfs%2F_view%2Frepcounts",
@@ -68,6 +75,10 @@ const designDoc = `
"map": "function (doc, meta) {\n if(doc.type == \"file\") { \n var idarr = meta.id.split(\"/\");\n emit(idarr, doc.length);\n }\n}",
"reduce": "_stats"
},
+ "garbage": {
+ "map": "function (doc, meta) {\n if (doc.type === 'blob') {\n emit(doc.garbage ? 'garbage' : 'live', doc.length);\n }\n}",
+ "reduce": "_stats"
+ },
"node_blobs": {
"map": "function (doc, meta) {\n if (doc.type === \"blob\") {\n for (var n in doc.nodes) {\n emit(n, null);\n }\n }\n}",
"reduce": "_count"
@@ -77,7 +88,7 @@ const designDoc = `
"reduce": "_sum"
},
"repcounts": {
- "map": "function (doc, meta) {\n if (doc.type === \"blob\") {\n var nreps = 0;\n for (var x in doc.nodes) {\n nreps++;\n }\n emit(nreps, null);\n }\n}",
+ "map": "function (doc, meta) {\n if (doc.type === \"blob\" && !doc.garbage) {\n var nreps = 0;\n for (var x in doc.nodes) {\n nreps++;\n }\n emit(nreps, null);\n }\n}",
"reduce": "_count"
}
}

0 comments on commit 27606bc

Please sign in to comment.