Github user garrensmith commented on a diff in the pull request:

    https://github.com/apache/couchdb/pull/221#discussion_r12520334
  
    --- 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');
    --- End diff --
    
    Lets only trigger a reload at the end of the loop. Otherwise every time we 
trigger a reload, it will do a fetch for the list of design docs. So rather 
just put a flag in this if statement, then check the flag after the loop has 
completed and decide if we need to trigger the `reloadDesignDocs` routeEvent.


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to