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

Patch second level cache association hydration #1382

Merged
merged 6 commits into from
Apr 14, 2015
Merged

Patch second level cache association hydration #1382

merged 6 commits into from
Apr 14, 2015

Conversation

holtkamp
Copy link
Contributor

Fixed incorrect use of keys in DefaultRegion::getMultiple() and simplified overall mechanism

@doctrinebot
Copy link

Hello,

thank you for creating this pull request. I have automatically opened an issue
on our Jira Bug Tracker for you. See the issue link:

http://www.doctrine-project.org/jira/browse/DDC-3689

We use Jira to track the state of pull requests and the versions they got
included in.

array_map([$this->cache, 'fetch'], $keysToRetrieve),
function ($retrieved) {
return false !== $retrieved;
$result = array();
Copy link
Member

Choose a reason for hiding this comment

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

You can use a early return whenever you have a missing entry.

<?php
$result = array();

foreach ($collection->identifiers as $key) {
    $entryKey   = $this->getCacheEntryKey($key);
    $entryValue = $this->cache->fetch($entryKey);

    if ($entryValue === false) {
        return null;
    }

    $result[] = $entryValue;
}

return $result;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I know and I know Doctrine uses a lot of early returns. Not my favorite though, I prefer the 'one return per function' approach.

Not sure whether it is a formal Doctrine code convention?

Copy link
Member

Choose a reason for hiding this comment

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

@holtkamp please use an early return: it's less confusing to follow

Copy link
Member

Choose a reason for hiding this comment

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

@holtkamp it's not a convention from Doctrine, but we should make it.
There is clear advantage of applying early returns; you increase code readability, reduce the cyclomatic complexity of your algorithm and also have fewer bytecode instructions to follow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, clear. A senior colleague (Java guy) once taught me to use only one
return per function to ease up debugging (only one breakpoint per function
required), since then I adopted it as a daily habit. But it is fine by me,
I regard more as a 'style' thingy ;).

Just pushed and update of the PR.

On 14 April 2015 at 16:15, Guilherme Blanco [email protected]
wrote:

In lib/Doctrine/ORM/Cache/Region/DefaultRegion.php
#1382 (comment):

@@ -100,30 +102,28 @@ public function get(CacheKey $key)
*/
public function getMultiple(CollectionCacheEntry $collection)
{

- $keysToRetrieve = array();

  •    foreach ($collection->identifiers as $index => $key) {
    
  •        $keysToRetrieve[$index] = $this->name . '_' . $key->hash;
    

- }

  •    $items = array_filter(
    
  •        array_map([$this->cache, 'fetch'], $keysToRetrieve),
    
  •        function ($retrieved) {
    
  •            return false !== $retrieved;
    
  •    $result = array();
    

@holtkamp https://github.com/holtkamp it's not a convention from
Doctrine, but we should make it.
There is clear advantage of applying early returns; you increase code
readability, reduce the cyclomatic complexity of your algorithm and also
have fewer bytecode instructions to follow.


Reply to this email directly or view it on GitHub
https://github.com/doctrine/doctrine2/pull/1382/files#r28330003.

Copy link
Member

Choose a reason for hiding this comment

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

@Ocramius Ocramius self-assigned this Apr 14, 2015
guilhermeblanco added a commit that referenced this pull request Apr 14, 2015
…iation-hydration

Patch second level cache association hydration
@guilhermeblanco guilhermeblanco merged commit 5f18618 into doctrine:master Apr 14, 2015
@guilhermeblanco
Copy link
Member

👍

@holtkamp holtkamp deleted the patch-second-level-cache-association-hydration branch April 14, 2015 15:40
guilhermeblanco added a commit that referenced this pull request Apr 14, 2015
…iation-hydration

Patch second level cache association hydration
@Ocramius Ocramius assigned guilhermeblanco and unassigned Ocramius Apr 15, 2015
@holtkamp
Copy link
Contributor Author

Would this bugfix justify a new release (for example 2.5.1)? Looking forward to using the SLC...

@Ocramius
Copy link
Member

It landed in the 2.5 branch at 3e6c6af

We have 2 or 3 bad bugs that require attention, then I'm tagging 2.5.1

@holtkamp
Copy link
Contributor Author

@Ocramius, it has been an month now, isn't a 2.5.1 patch version justified to at least fix 1 serious bug? For the other mentioned bugs new patch versions can be used according to www.semver.org, right?

@stof
Copy link
Member

stof commented May 22, 2015

@Ocramius it would be great to fix the tests in the 2.5 branch btw

@holtkamp
Copy link
Contributor Author

@stof what (broken) tests are you referring to? Is a 2.5.1 version still being aimed for or... @Ocramius what 2 to 3 bad bugs were you referring to that impede a 2.5.1 patch version? Maybe I can help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants