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

Add runtime cache to Zend_Locale_Data #918

Merged
merged 1 commit into from
Apr 21, 2020

Conversation

tmotyl
Copy link
Contributor

@tmotyl tmotyl commented Apr 4, 2020

Fixes: #917
This imporves performance,as Zend is not calling cache backend multiple times for locale information.

@tmotyl tmotyl added the performance Performance related label Apr 4, 2020
@colinmollenhour
Copy link
Member

Minor improvement: might as well save the result ($temp) in the local cache as well at the end of the getList method to avoid reading from cache or when a cache backend is disabled.

@colinmollenhour
Copy link
Member

Haha, I just realized that this PR is based on my patch from almost 8 years ago! Thanks for digging it up!

@tmotyl
Copy link
Contributor Author

tmotyl commented Apr 6, 2020

yep, oldi but goldi ;)
I've stu,mbled upon similar issues when working with Magento 2. magento/magento2#20973

@tmotyl tmotyl force-pushed the zend_locale_data_runtime_cache branch from cd5d7e9 to a1fcb81 Compare April 6, 2020 20:00
@colinmollenhour colinmollenhour merged commit 48939f0 into 1.9.4.x Apr 21, 2020
}
static::$_localCache['id'] = $data;

Choose a reason for hiding this comment

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

@tmotyl
why this key used 'id' ?
should it be the $id variable ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

damn, it should. Can you make a PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

and in line 1526 too

Copy link
Contributor

Choose a reason for hiding this comment

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

one reason, why its always good to wait for a second Review 👀

colinmollenhour added a commit that referenced this pull request May 14, 2020
@colinmollenhour
Copy link
Member

Fixed in 8b89754. Thanks @ilnytskyi!

@ilnytskyi
Copy link

We tried this patch with M2 and we got an error :)

{"message":"Warning: Illegal string offset 'decimal' in /var/www/html/vendor/magento/zendframework1/library/Zend/Locale/Format.php on line 427","context":[],"level":500,"level_name":"CRITICAL","channel":"main"}

tmotyl pushed a commit to macopedia/magento-lts that referenced this pull request May 14, 2020
tmotyl pushed a commit to macopedia/magento-lts that referenced this pull request May 14, 2020
@@ -985,7 +1001,9 @@ public static function getContent($locale, $path, $value = false)
$val = urlencode($val);
$id = self::_filterCacheId('Zend_LocaleC_' . $locale . '_' . $path . '_' . $val);
if (!self::$_cacheDisabled && ($result = self::$_cache->load($id))) {

Choose a reason for hiding this comment

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

btw if I understand correctly lack of

        // add runtime cache to avoid callng cache backend multiple times during one request
        if (isset(self::$_localCache[$id])) {
            return self::$_localCache[$id];
        }

before the if will trigger $_cache->load($id) and data is not taken from runtime

Noticed that after the patch we anyway have many Zend_LocaleC_ coming from cache

Copy link
Contributor Author

Choose a reason for hiding this comment

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

can you propose a patch/pull request? thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#1018
I've pushed the change, and tested it.

tmotyl added a commit to macopedia/magento-lts that referenced this pull request Jun 3, 2020
tmotyl added a commit to macopedia/magento-lts that referenced this pull request Jun 3, 2020
tmotyl added a commit to macopedia/magento-lts that referenced this pull request Jun 4, 2020
tmotyl added a commit to macopedia/magento-lts that referenced this pull request Jun 4, 2020
@sreichel sreichel deleted the zend_locale_data_runtime_cache branch June 5, 2020 02:19
tmotyl added a commit to macopedia/magento-lts that referenced this pull request Jun 5, 2020
@kiatng
Copy link
Contributor

kiatng commented Jun 12, 2020

We ran into seemingly random warnings in both frontend and backend:

Warning: Invalid argument supplied for foreach() in lib/Zend/Locale/Format.php on line 853

Code adjacent to line 853:

// erase day string
    $daylist = Zend_Locale_Data::getList($options['locale'], 'day');
foreach($daylist as $key => $name) {
    if (iconv_strpos($number, $name) !== false) {
        $number = str_replace($name, "EEEE", $number);
        break;
    }

$daylist is a serialized string:

a:7:{s:3:"sun";s:6:"Sunday";s:3:"mon";s:6:"Monday";s:3:"tue";s:7:"Tuesday";s:3:"wed";s:9:"Wednesday";s:3:"thu";s:8:"Thursday";s:3:"fri";s:6:"Friday";s:3:"sat";s:8:"Saturday";}

Not sure if #1018 would fix it.

[edit]
Saw that this is fixed in PR #979.

tmotyl added a commit to macopedia/magento-lts that referenced this pull request Jun 23, 2020
tmotyl added a commit that referenced this pull request Jun 24, 2020
@sreichel sreichel added this to the Release 19.4.4 milestone Jun 26, 2020
edannenberg pushed a commit to edannenberg/magento-lts that referenced this pull request Aug 20, 2020
edannenberg pushed a commit to edannenberg/magento-lts that referenced this pull request Aug 24, 2020
randallelliott714 added a commit to randallelliott714/magento that referenced this pull request Oct 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement performance Performance related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add runtime cache to zend locale data
6 participants