Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Model::save() may call unneeded countAllResults() #5439

Merged
merged 3 commits into from
Dec 7, 2021

Conversation

kenjis
Copy link
Member

@kenjis kenjis commented Dec 6, 2021

Description
When useAutoIncrement is disabled, countAllResults() is called, even if $data does not have id value.
You'll see the query like the following:

SELECT COUNT(*AS `numrows` FROM `news` WHERE `id` IS NULL
<?php

function f1() {
  return false && false ? true : 'a';
}
function f2() {
  return false && (false ? true : 'a');
}

var_dump(f1()); // "a"
var_dump(f2()); // false

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@kenjis kenjis added bug Verified issues on the current code behavior or pull requests that will fix them database Issues or pull requests that affect the database layer labels Dec 6, 2021
@kenjis
Copy link
Member Author

kenjis commented Dec 6, 2021

Copy link
Member

@paulbalandan paulbalandan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure what happened, but I think it was an error. 😂

Complex conditions cause bugs.
@kenjis
Copy link
Member Author

kenjis commented Dec 6, 2021

Don't worry. Nobody's perfect.

I thought if php-cs-fixer causes this error, we have to check the rule.
But now I run php-cs-fixer, ( ) are not removed.

I don't like long conditions. It is difficult to read and do step debugging.
I refactored.

system/Model.php Outdated Show resolved Hide resolved
Copy link
Member

@paulbalandan paulbalandan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new code looks much better and understandable. 👍

@kenjis kenjis merged commit 1e036bc into codeigniter4:develop Dec 7, 2021
@kenjis kenjis deleted the fix-Model-shouldUpdate branch December 7, 2021 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them database Issues or pull requests that affect the database layer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants