8000 [Cache] Fix storing binary keys when using pgsql by nicolas-grekas · Pull Request #49848 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Cache] Fix storing binary keys when using pgsql #49848

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

Merged
merged 1 commit into from
Mar 29, 2023

Conversation

nicolas-grekas
Copy link
Member
Q A
Branch? 5.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #49748
License MIT
Doc PR -

@fabpot
Copy link
Member
fabpot commented Mar 29, 2023

Thank you @nicolas-grekas.

@fabpot fabpot merged commit 2794527 into symfony:5.4 Mar 29, 2023
@nicolas-grekas nicolas-grekas deleted the cache-pg-bin branch March 29, 2023 21:26
nicolas-grekas added a commit that referenced this pull request Mar 29, 2023
…nt operator (weaverryan)

This PR was merged into the 5.4 branch.

Discussion
----------

[Cache] Fix php7 compat on 5.4: null coalescing assignment operator

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | None
| License       | MIT
| Doc PR        | Not needed

It looks like #49848 accidentally introduced a syntax not compat with php 7.2/7.3. So, an annoying little PR to fix that.

Commits
-------

7e5fe59 [Cache] Removing null coalescing assignment operator on 5.4
This was referenced Mar 31, 2023
*/
protected function getId($key)
{
if ('pgsql' !== $this->driver ?? ($this->getConnection() ? $this->driver : null)) {

Choose a reason for hiding this comment

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

This is one of the most difficult to read if statements I have come across in recent memory. Perhaps something like this would help ... ?

// Ensure that driver has been declared.
$this->getConnection();

if ('pgsql' !== $this->driver) {

Or maybe adding a getDriver() helper ... ?

/**
 * @return string|null
 */
private function getDriver()
{
    $this->getConnection(); // also defines driver

    return $this->driver;
}

Copy link
Member Author

Choose a reason for hiding this comment

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

this code path is on the hot path, it's written in a way that skips calling the method unless it's really needed

Copy link
@shadowhand shadowhand Apr 3, 2023

Choose a reason for hiding this comment

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

Okay, then how about:

/**
 * @return string
 */
private function getDriver()
{
    if (null === $this->driver) {
        $this->getConnection(); // defines driver
    }

    return $this->driver;
}

Copy link
Member Author

Choose a reason for hiding this comment

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

that's still add a method call on the hot path while we can avoid it

Choose a reason for hiding this comment

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

Is the micro-micro-micro optimization worth the cost of cognitive load? I guess that's for Symfony to decide...

Copy link
Member Author
@nicolas-grekas nicolas-grekas Apr 3, 2023

Choose a reason for hiding this comment

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

All µ-optims add up when they're on the hot path so 🤷

Choose a reason for hiding this comment

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

Sure, I understand that, but this is in a database backed cache adapter. Variance in latency/IO is going to have far more impact than one method call ever will. 🤷🏼‍♂️

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.

4 participants
0