couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From garrensmith <...@git.apache.org>
Subject [GitHub] couchdb pull request: Implement bulk deletion for all-docs-listing
Date Mon, 12 May 2014 09:46:33 GMT
Github user garrensmith commented on a diff in the pull request:

    https://github.com/apache/couchdb/pull/221#discussion_r12520506
  
    --- Diff: src/fauxton/app/addons/documents/resources.js ---
    @@ -295,6 +295,120 @@ function(app, FauxtonAPI, PagingCollection) {
     
       });
     
    +  Documents.BulkDeleteDoc = FauxtonAPI.Model.extend({
    +    idAttribute: "_id"
    +  });
    +
    +  Documents.BulkDeleteDocCollection = FauxtonAPI.Collection.extend({
    +
    +    model: Documents.BulkDeleteDoc,
    +
    +    initialize: function (models, options) {
    +      this.databaseId = options.databaseId;
    +    },
    +
    +    bulkDelete: function () {
    +      var payload = this.createPayload(this.toJSON()),
    +          that = this;
    +
    +      $.ajax({
    +        type: 'POST',
    +        url: app.host + '/' + this.databaseId + '/_bulk_docs',
    +        contentType: 'application/json',
    +        dataType: 'json',
    +        data: JSON.stringify(payload),
    +      })
    +      .then(function (res) {
    +        that.handleResponse(res);
    +      })
    +      .fail(function () {
    +        var ids = _.reduce(this.toArray(), function (acc, doc) {
    +          acc.push(doc.id);
    +          return acc;
    +        }, []);
    +        that.trigger('error', ids);
    +      });
    +    },
    +
    +    handleResponse: function (res) {
    +      var errorIds = [],
    +          successIds = [],
    +          doc;
    +
    +      for (doc in res) {
    +        if (res[doc].error) {
    +          errorIds.push(res[doc].id);
    +        }
    +        if (res[doc].ok === true) {
    +          successIds.push(res[doc].id);
    +        }
    +      }
    +
    +      this.removeDocuments(successIds);
    +
    +      if (!errorIds.length) {
    +        this.clear();
    +      } else {
    +        this.trigger('error', errorIds);
    +        this.save();
    +      }
    +
    +      this.trigger('updated');
    +    },
    +
    +    removeDocuments: function (ids) {
    +      _.each(ids, function (id) {
    +        if (/_design/.test(id)) {
    +          FauxtonAPI.triggerRouteEvent('reloadDesignDocs');
    +        }
    +
    +        this.remove(this.get(id));
    +      }, this);
    +
    +      this.trigger('removed', ids);
    +    },
    +
    +    createList: function (documents) {
    +      var documentList = [],
    --- End diff --
    
    This whole method could just be a _.map function
    
        return _.map(documents, function (doc) { return doc.id; }


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message