Views BulkForm should automatically create batch when certain number of entities are selected for performance issues in it's submit handler which is not difficult task at all.
This number should be optional in the BulkForm options 'form'. Also there should be another option to split the entities into chunks so the batch would run faster(also not difficult at all).

I'd write a patch but BulkForm submission is broken in A10 #2239245: BulkForm does not work in Block display

Comments

Anonymous’s picture

StatusFileSize
new4.78 KB

Something like this(untested).

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

mglaman’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 1: bulkform-batch.patch, failed testing. View results

andypost’s picture

Version: 8.6.x-dev » 8.7.x-dev
Issue tags: +Needs reroll
vacho’s picture

StatusFileSize
new6.51 KB

The code at core/modules/system/lib/Drupal/system/Plugin/views/field/BulkForm.php has been moved to core/modules/system/src/Plugin/views/field/BulkForm.php and this has been deprecated, so the functional code is in: core/modules/views/src/Plugin/views/field/BulkForm.php

Patch applied to current logic.

vacho’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
manuel garcia’s picture

First, I love this idea, let's do it!

+++ b/core/modules/views/src/Plugin/views/field/BulkForm.php
@@ -250,6 +252,23 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
+    $form['batch_limit'] = [
+      '#type' => 'number',
+      '#title' => $this->t('Batch limit'),
+      '#default_value' => $this->options['batch_limit'],
+      '#description' => $this->t("When the number of selected items reach or exceeds this number a batch will be used to perform selected action. Set to 0 to never use batch processing."),
+      '#min' => 0
+    ];

@@ -404,40 +423,48 @@ public function viewsFormSubmit(&$form, FormStateInterface $form_state) {
+      if (!empty($this->options['batch_limit']) && count($entities) >= $this->options['batch_limit']) {
+        // Create batch.
+        $this->createBatch($entities, $action);
+      } else{
+        // Otherwise proceed as usual.

I find the batch_limit option confusing, and I believe UI users will as well.

I'd like to propose a solution to this:

  • Use a checkbox to enable batching instead of batch_limit being more than 1.
  • Only show the batch_chunk option in the form if the batch enable checkbox is checked.
  • Use the checkbox value and batch_chunk < count($entities) to determine if we createBatch or not.
manuel garcia’s picture

Title: Views BulkForm should automatically use batch with option to chunk it » Have Views BulkForm optioinally use batching with an option to chunk it
Category: Task » Feature request

This is would be a new feature, so changing the category.

manuel garcia’s picture

Title: Have Views BulkForm optioinally use batching with an option to chunk it » Have Views BulkForm optionally use batching with an option to chunk it

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

vacho’s picture

Status: Needs review » Needs work
andypost’s picture

Issue tags: +Needs tests
YurkinPark’s picture

Patch doesn't work for me for several reasons

+      if (!empty($this->options['batch_limit']) && count($entities) >= $this->options['batch_limit']) {

Need to count with "$selected" variable, $entities variable is empty at this moment. So, batch will never be created. But main reason is some actions (like delete) need a confirmation before action. It means, even we will process executing of delete action in batch, delete action will do nothing during batch session (because it is just creating list of what to confirm). To implement this, we will need changes inside these confirm forms (to catch some context may be with stored info about batch operation)

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

manuel garcia’s picture

Status: Needs work » Needs review
StatusFileSize
new5.4 KB
new7.17 KB

Only patch cleanup here. Setting to needs review for the tests to run, but this is still needs work.

manuel garcia’s picture

StatusFileSize
new910 bytes
new6.88 KB

more cleanup

andypost’s picture

Related issues: +#2909423: Get rid of BulkForm subclasses when they just override emptySelectedMessage
manuel garcia’s picture

StatusFileSize
new695 bytes
new7.56 KB

For now just enabled batching on the test view used to test the bulkform functionality.

manuel garcia’s picture

Adding related issue which demonstrates that you can setup an Action to use batching in code, which is probably a first step in this direction.

Status: Needs review » Needs work

The last submitted patch, 24: 2239269-24.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

manuel garcia’s picture

Status: Needs work » Needs review
StatusFileSize
new542 bytes
new8.09 KB

Adding the schema for batch_limit and batch_chunk

Status: Needs review » Needs work

The last submitted patch, 27: 2239269-27.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

andypost’s picture

btw core using config and settings variables to define default batch size (around 50) so min-max should be considered to be higher

$batch_size = Settings::get('entity_update_batch_size', 50);
...
$limit = \Drupal::config('field.settings')->get('purge_batch_size');
andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new9.77 KB
new4.46 KB

If we introduce this option then makes sense to adopt it to administrative views and consider default batch size

Also patch fixes config schema naming (chunk instead of chunks)

manuel garcia’s picture

Re #30:

Thanks for fixing the schema there, oops!

If we introduce this option then makes sense to adopt it to administrative views and consider default batch size

Until #2603820: [PP-1] Allow selecting all entities in a given page or in every pages for bulk operations gets done, doing this would not have any effect since we can't select more items than what's shown on the the first page.
Since these updates mean we'd need an upgrade path & upgrade path tests for the views, I propose we enable this option on #2603820: [PP-1] Allow selecting all entities in a given page or in every pages for bulk operations instead of here, since that’s where it would actually become usable.

batkor’s picture

subscribe

lendude’s picture

Status: Needs review » Needs work
+++ b/core/modules/views/src/Plugin/views/field/BulkForm.php
@@ -250,6 +253,23 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
     parent::buildOptionsForm($form, $form_state);

@@ -404,40 +424,49 @@ public function viewsFormSubmit(&$form, FormStateInterface $form_state) {
+        $this->createBatch($entities, $action);

at this point entities is always an empty array right? so I'm assuming this is a work in progress? or am I overlooking something?

We'd need an upgrade path and test for the config change. And obviously tests for the new functionality.

matroskeen’s picture

Assigned: Unassigned » matroskeen
matroskeen’s picture

Assigned: matroskeen » Unassigned
StatusFileSize
new10.6 KB
new7.83 KB

Remaining items:

  • handle actions with confirmation step;
  • add tests.

I'm not sure that any upgrade path is needed, because we have default values for these options.

YurkinPark’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 35: 2239269-35.patch, failed testing. View results

longwave’s picture

I agree with #13 in that I am not sure why batch_limit isn't just a checkbox - what is the use case for having batch_limit anything other than 0 or the same value as batch_chunk? A lower number doesn't make sense at all, and I can't see a good reason for allowing a higher number either.

In fact, do we even need a checkbox? If batch_chunk is 0 then disable batching, otherwise split the batch into that many chunks?

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

andypost’s picture

Issue tags: +Needs reroll
kishor_kolekar’s picture

Assigned: Unassigned » kishor_kolekar
kishor_kolekar’s picture

StatusFileSize
new10.89 KB

I have re-roll the patch.

kishor_kolekar’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 42: 3142893-42.patch, failed testing. View results

andypost’s picture

Issue tags: -Needs reroll
kishor_kolekar’s picture

Assigned: kishor_kolekar » Unassigned

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.