From dd7f1098782e9fe94f6b9aeccb0a1384c02f110b Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Sun, 14 Dec 2008 17:29:15 -0600 Subject: [PATCH] Add support for database compaction. --- lib/couchrest/core/database.rb | 7 ++++++- spec/couchrest/core/database_spec.rb | 12 +++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/couchrest/core/database.rb b/lib/couchrest/core/database.rb index 6f19128..184d362 100644 --- a/lib/couchrest/core/database.rb +++ b/lib/couchrest/core/database.rb @@ -149,7 +149,12 @@ module CouchRest slug = CGI.escape(doc['_id']) CouchRest.delete "#{@root}/#{slug}?rev=#{doc['_rev']}" end - + + # Compact the database, removing old document revisions and optimizing space use. + def compact! + CouchRest.post "#{@root}/_compact" + end + # DELETE the database itself. This is not undoable and could be rather # catastrophic. Use with care! def delete! diff --git a/spec/couchrest/core/database_spec.rb b/spec/couchrest/core/database_spec.rb index 5fb2e70..1be153c 100644 --- a/spec/couchrest/core/database_spec.rb +++ b/spec/couchrest/core/database_spec.rb @@ -461,6 +461,16 @@ describe CouchRest::Database do end end + + describe "compacting a database" do + it "should compact the database" do + db = @cr.database('couchrest-test') + # r = + db.compact! + # r['ok'].should == true + end + end + describe "deleting a database" do it "should start with the test database" do @cr.databases.should include('couchrest-test') @@ -475,4 +485,4 @@ describe CouchRest::Database do end -end \ No newline at end of file +end