API page: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21State%21S...

State::delete() calls parent::delete(), and then State::deleteMultiple(), which then calls parent::delete() for each of the received keys.

State::delete() should just calls State::deleteMultiple(), and the code would become the following.

public function delete($key) {
  $this->deleteMultiple([$key]);
}
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kiamlaluno created an issue. See original summary.

apaderno’s picture

Status: Active » Needs review
FileSize
404 bytes

Status: Needs review » Needs work

The last submitted patch, 2: remove-parent-delete-2884223-2.patch, failed testing. View results

apaderno’s picture

Status: Needs work » Needs review
FileSize
406 bytes

Moving the file from Ubuntu, I lost a new line.

Status: Needs review » Needs work

The last submitted patch, 4: remove-parent-delete-2884223-4.patch, failed testing. View results

apaderno’s picture

Status: Needs work » Needs review
FileSize
397 bytes
apaderno’s picture

It makes more sense to simply change the code as follows.

public function delete($key) {
  parent::delete($key);
  $this->keyValueStore->delete($key);
}

It doesn't make sense to call $this->deleteMultiple([$key]), which needs to loop over an array containing a single item, just to avoid calling $this->keyValueStore->delete($key) directly.

apaderno’s picture

Dinesh18’s picture

Status: Needs review » Reviewed & tested by the community

I looked into both the delete and deleteMultiple API page. If you will look into the deleteMultiple , they have just used foreach for keys. So, for delete we just need to remove the foreach and rest remains the same.
#8 looks great to me. Changing the status to RTBC.

Wim Leers’s picture

Title: parent::delete($key) is called twice » In \Drupal\Core\State\State, parent::delete($key) is called twice

Clarifying title.

larowlan’s picture

Looks good to me

  • catch committed a75874b on 8.4.x
    Issue #2884223 by kiamlaluno, Dinesh18: In \Drupal\Core\State\State,...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed a75874b and pushed to 8.4.x. Thanks!

apaderno’s picture

Version: 8.4.x-dev » 8.3.x-dev
Status: Fixed » Needs review
FileSize
425 bytes

Should I provide the patch also for previous versions?

Dinesh18’s picture

Status: Needs review » Reviewed & tested by the community

Patch #14 looks good to me.
Changing the status to RTBC.

Gábor Hojtsy’s picture

Version: 8.3.x-dev » 8.4.x-dev
Status: Reviewed & tested by the community » Fixed

I think if @catch intended to cherry-pick to Drupal 8.3.x, he would have. I don't think it does harm to cherry-pick neither it does harm to not, so going to move this back to 8.4.x fixed. Thanks for providing the patch either way!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.