Updated Branches: refs/heads/1809-compact-and-clean [created] 6f9661e7f
compact and clean up working Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/1ca8d09d Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/1ca8d09d Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/1ca8d09d Branch: refs/heads/1809-compact-and-clean Commit: 1ca8d09da0c1e05362e18d972a3fe943a70ae4fe Parents: f6862f2 Author: Garren Smith <[email protected]> Authored: Wed Oct 16 13:24:09 2013 +0200 Committer: Garren Smith <[email protected]> Committed: Wed Oct 16 13:33:04 2013 +0200 ---------------------------------------------------------------------- .../compaction/assets/less/compaction.less | 8 +++ src/fauxton/app/addons/compaction/resources.js | 17 ++++++ .../app/addons/compaction/templates/layout.html | 33 +++++++----- src/fauxton/app/addons/compaction/views.js | 56 +++++++++++++++++++- src/fauxton/settings.json.default | 4 +- 5 files changed, 103 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb/blob/1ca8d09d/src/fauxton/app/addons/compaction/assets/less/compaction.less ---------------------------------------------------------------------- diff --git a/src/fauxton/app/addons/compaction/assets/less/compaction.less b/src/fauxton/app/addons/compaction/assets/less/compaction.less new file mode 100644 index 0000000..c197d9a --- /dev/null +++ b/src/fauxton/app/addons/compaction/assets/less/compaction.less @@ -0,0 +1,8 @@ + +.compaction-option { + background-color: #F7F7F7; + border: 1px solid #DDD; + margin-bottom: 30px; + padding: 10px; + +} http://git-wip-us.apache.org/repos/asf/couchdb/blob/1ca8d09d/src/fauxton/app/addons/compaction/resources.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/addons/compaction/resources.js b/src/fauxton/app/addons/compaction/resources.js index d0180ef..b6fa4bc 100644 --- a/src/fauxton/app/addons/compaction/resources.js +++ b/src/fauxton/app/addons/compaction/resources.js @@ -17,5 +17,22 @@ define([ function (app, FauxtonAPI) { var Compaction = FauxtonAPI.addon(); + + Compaction.compactDB = function (db) { + return $.ajax({ + url: db.url() + '/_compact', + contentType: 'application/json', + type: 'POST' + }); + }; + + Compaction.cleanupViews = function (db) { + return $.ajax({ + url: db.url() + '/_view_cleanup', + contentType: 'application/json', + type: 'POST' + }); + } + return Compaction; }); http://git-wip-us.apache.org/repos/asf/couchdb/blob/1ca8d09d/src/fauxton/app/addons/compaction/templates/layout.html ---------------------------------------------------------------------- diff --git a/src/fauxton/app/addons/compaction/templates/layout.html b/src/fauxton/app/addons/compaction/templates/layout.html index 56bcbc2..08a2078 100644 --- a/src/fauxton/app/addons/compaction/templates/layout.html +++ b/src/fauxton/app/addons/compaction/templates/layout.html @@ -11,17 +11,26 @@ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> +<div class="row"> + <div class="span12 compaction-option"> + <h3> Compact Database </h3> + <p>Compacting a database removes deleted documents and previous revisions. It is an irreversible operation and may take a while to complete for large databases.</p> + <button id="compact-db" class="btn btn-large btn-primary"> Run </button> + </div> +</div> -<table class="table table-striped table-bordered"> - <tbody> - <tr> - <td> - <h3> Compact Database </h3> - <p>Compacting a database removes deleted documents and previous revisions. It is an irreversible operation and may take a while to complete for large databases.</p> - <button id="compact-db" class="btn btn-large btn-primary"> Run </button> - </td> - </tr> - </tbody> - -</table> +<div class="row"> + <div class="span12 compaction-option"> + <h3> Compact Views </h3> + <p>View compaction will affect all views in this design document. This operation may take some time to complete. Your views will still operate normally during compaction.</p> + <button id="compact-view" class="btn btn-large btn-primary"> Run </button> + </div> +</div> +<div class="row"> + <div class="span12 compaction-option"> + <h3> Cleanup Views </h3> + <p>Cleaning up views in a database removes old view files still stored on the filesystem. It is an irreversible operation.</p> + <button id="cleanup-views" class="btn btn-large btn-primary"> Run </button> + </div> +</div> http://git-wip-us.apache.org/repos/asf/couchdb/blob/1ca8d09d/src/fauxton/app/addons/compaction/views.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/addons/compaction/views.js b/src/fauxton/app/addons/compaction/views.js index 67afd5e..457e5f6 100644 --- a/src/fauxton/app/addons/compaction/views.js +++ b/src/fauxton/app/addons/compaction/views.js @@ -23,12 +23,66 @@ function (app, FauxtonAPI, Compaction) { Compaction.Layout = FauxtonAPI.View.extend({ template: 'addons/compaction/templates/layout', + initialize: function () { + _.bindAll(this); + }, + events: { - "click compact-db": "compactDB" + "click #compact-db": "compactDB", + "click #compact-view": "compactDB", + "click #cleanup-views": "cleanupViews" + }, + + disableButton: function (selector, text) { + this.$(selector).attr('disabled', 'disabled').text(text); + }, + + enableButton: function (selector, text) { + this.$(selector).removeAttr('disabled').text(text); }, compactDB: function (event) { + var enableButton = this.enableButton; event.preventDefault(); + + this.disableButton('#compact-db', 'Compacting...'); + + Compaction.compactDB(this.model).then(function () { + FauxtonAPI.addNotification({ + type: 'success', + msg: 'Database compaction has started.' + }); + }, function (xhr, error, reason) { + console.log(arguments); + FauxtonAPI.addNotification({ + type: 'error', + msg: 'Error: ' + JSON.parse(xhr.responseText).reason + }); + }).always(function () { + enableButton('#compact-db', 'Run'); + }); + }, + + cleanupViews: function (event) { + var enableButton = this.enableButton; + event.preventDefault(); + + this.disableButton('#cleanup-view', 'Cleaning...'); + + Compaction.cleanupViews(this.model).then(function () { + FauxtonAPI.addNotification({ + type: 'success', + msg: 'View cleanup has started.' + }); + }, function (xhr, error, reason) { + console.log(arguments); + FauxtonAPI.addNotification({ + type: 'error', + msg: 'Error: ' + JSON.parse(xhr.responseText).reason + }); + }).always(function () { + enableButton('#cleanup-views', 'Run'); + }); } http://git-wip-us.apache.org/repos/asf/couchdb/blob/1ca8d09d/src/fauxton/settings.json.default ---------------------------------------------------------------------- diff --git a/src/fauxton/settings.json.default b/src/fauxton/settings.json.default index 54cc0ce..1b68911 100644 --- a/src/fauxton/settings.json.default +++ b/src/fauxton/settings.json.default @@ -8,9 +8,9 @@ { "name": "plugins" }, { "name": "contribute" }, { "name": "permissions" }, - { "name": "verifyinstall" } { "name": "compaction" }, - { "name": "auth" } + { "name": "auth" }, + { "name": "verifyinstall" } ], "template": { "development": {
