Smile-SA / magento2-module-store-locator

Magento 2 store locator module
50 stars 57 forks source link

Prevent excessive locale fetches from redis #49

Closed WinstonN closed 5 years ago

WinstonN commented 5 years ago

I saw many locale lookups (~3500 hget calls) on a product/view page with $this->getCurrentMode() === Navigation::DRIVE_MODE

1560323938.063142 [2 unix:/tmp/redis.sock] "hget" "zc:k:2b3_Zend_LocaleL_en_GB_day_" "d"
1560323938.245287 [2 unix:/tmp/redis.sock] "hget" "zc:k:2b3_Zend_LocaleL_en_GB_month_" "d"
1560323938.425919 [2 unix:/tmp/redis.sock] "hget" "zc:k:2b3_Zend_LocaleL_en_GB_month_gregorian_format_abbreviated" "d"
1560323938.602275 [2 unix:/tmp/redis.sock] "hget" "zc:k:2b3_Zend_LocaleC_en_NZ_time_short" "d"
1560324031.566040 [2 unix:/tmp/redis.sock] "hget" "zc:k:2b3_Zend_LocaleC_en_NZ_am_" "d"

This PR tries to fix that by setting the locale in memory, then using strftime to get the date format

cat /tmp/hget_before.txt |wc -l
    3674

cat /tmp/hget_after_code_change.txt |wc -l
     528
IvanChepurnyi commented 5 years ago

Hey @WinstonN, try this one instead:

// before loop starts
$formatter = new IntlDateFormatter('locale_code', IntlDateFormatter::NONE, IntlDateFormatter::SHORT);

// use instead of private method call in the loop
$formatter->format(DateTime::createFromFormat('Y-m-d H:i:s', $date));