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

Needs id so static var doesn't persist across object. #2715

Merged
merged 1 commit into from
Aug 9, 2024
Merged

Conversation

ideadude
Copy link
Member

@ideadude ideadude commented Aug 9, 2024

The commit here attempted to cache the order total through a static var: 482b119

However, that static var persists across separate instances of the order object!

Here is an example to demonstrate:

class Test {
    public function echovar()  {
        static $var = 0;
        $var++;
        echo $var;
    }
}

$t1 = new Test();
$t1->echovar(); // echos 1

$t2 = new Test();
$t2->echovar(); // echos 2, we expected 1

To fix this, this PR uses the order id in the cache array.

It's still possible that multiple calls to this method before and after tweaking the revenue somehow may result in the wrong cached version being returned, but this doesn't seem to happen in practice. The performance improvement of the orders page is worth it until we find a new way to grab things there.

@ideadude ideadude merged commit 27eb3e3 into dev Aug 9, 2024
37 of 43 checks passed
@ideadude ideadude deleted the fix/revenue branch August 9, 2024 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

1 participant