mage2tv / magento-cache-clean

A faster drop in replacement for bin/magento cache:clean with file watcher
BSD 3-Clause "New" or "Revised" License
532 stars 63 forks source link

Not working with Ui component changes #32

Closed zaheerbadi closed 5 years ago

zaheerbadi commented 5 years ago

I m running this in windowns environment and Magento2.2.7 instance so the issue is when try to change in Ui component listing xml file it trigger to remove specific id cache but when i refresh browser it doesn't actually remove cache i have to remove cache using magento command every time. Here is how it run. http://prntscr.com/n4hd3r

Vinai commented 5 years ago

Hi @zaheerbadi , thanks for the issue report! Windows support is still a bit dev-stability, because I don't have a windows box available and I haven't found someone yet who is willing to work with me resolving existing issues. So I might end up asking more questions before providing an answer.

First, do other cache cleaning operations work, e.g. if you alter a di.xml file, does the config cache get cleaned successfully? Of if you change a .phtml templage or layout XML file, does that clean the full page cache?

zaheerbadi commented 5 years ago

Thanks @Vinai

First, do other cache cleaning operations work, e.g. if you alter a di.xml file, does the config cache get cleaned successfully? Of if you change a .phtml templage or layout XML file, does that clean the full page cache?

Yes its cleaning full_page and block_html cache on changing of phtml file

Vinai commented 5 years ago

Okay, that's good. Now, I expect there is an issue with the internal ui component name and the file name not matching in the same way the core ui component instances are named, so the generated cache ID doesn't match the real cache ID. Can you please run the file watcher with the flag -vvv to turn on debug output. Then please try editing the ui component file in question again and paste the output related to the change here.

zaheerbadi commented 5 years ago

http://prntscr.com/n4mqh9

Vinai commented 5 years ago

Thank you! Here is a though dump based on the information I have. I'm writing this down for myself as much as for you if you happen to be interested, too.

According to vendor/magento/module-ui/Config/Data.php line 86 the cache ID for that UI component configuration should be $this->cacheId = static::CACHE_ID . '_' . $componentName;. Since your file name is cda_ingredients_ingredent_form.xml, this means the cache ID is ui_component_configuration_data_cda_ingredients_ingredent_form. The output indicates that it can't find a file matching that cache ID. It's my assumption the problem is caused by an incorrect mapping of the cache ID to a file. Maybe this is an issue specific to windows.

Currently the file names the app looks to delete can not be output by switching on debug output. I'll create a build with additional debug output and ask you to install that version and run it again, so we can compare what file it tries to delete against the actual contents of the file system.

I'll post instructions here shortly as soon as I've created the branch.

Vinai commented 5 years ago

Please run the following commands to install the issue specific version:

composer remove --dev mage2tv/magento-cache-clean
composer require --dev mage2tv/magento-cache-clean:dev-issue-32-id-cleaning-on-win

If you installed the package globally, please use composer global instead.

Then run the watcher wilth -vvv and edit the file again. It should spit out the file name it is looking for when attempting to delete the cache ID. The please check if that file of a similar one exists. Thanks for your help!

zaheerbadi commented 5 years ago

@Vinai Thank you for your valuable time to spend on it.

But unfortunately it still not working http://prntscr.com/n5puvw It seems command try to delete it from the var/cache/mage--7/mage---f21_UI_COMPONENT_CONFIGURATION_DATA_CDA_INGREDIENTS_INGREDENT_LISTING but it actually present in var/cache/mage--e/mage---00a_UI_COMPONENT_CONFIGURATION_DATA_CDA_INGREDIENTS_INGREDENT_LISTING

Vinai commented 5 years ago

Thank you for the additional info! This is useful.

It probably would be possible to configure a workaround by adding a cache id-prefix in app/etc/env.php, but it would be nice if the tool "just worked".

Would you be willing to help me debug this a little bit further if I tell you what steps to take?


Notes for myself:

The id prefix (mage---f21 in the example above) is generated in magento/app.cljs with

(str (subs (storage/md5 (str (fs/realpath (base-dir)) "/app/etc/")) 0 3) "_")

It is dependent on the file system path to the Magento instance app/etc directory.

However, the prefix can also be configured in app/etc/env.php for the cache by adding a key id_prefix to the default and page_cache config.

The cache-dir suffix (mage--7 in the example above) is generated in cache/storage/file.cljs with

(let [suffix (chars-from-end (storage/md5 id) 1)]
   (str cache-dir "mage--" suffix "/"))

So it is directly dependent on the cache ID, NOT the file system. If the ID prefix where fixed, the cache dir suffix would most likely match the actual path then, too.

I assume the issue happens because Magento calculates the id prefix based on a different path string, maybe because of directory separator differences.

Next steps:

zaheerbadi commented 5 years ago

@Vinai have try to output from vendor/magento/framework/App/Cache/Frontend/Factory.php it's 00a_.

But Output the path used in magento/app.cljs on line 20. i can't able to get this point

Latest screen http://prntscr.com/n69979

Vinai commented 5 years ago

@zaheerbadi Thank you - I didn't expect you to already provide the output. Those where more notes for myself to more easily pick up the train of thought again.

In the Cache\Frontend\Factory, I actually need the value from $configDirPath, not the $idPrefix. Could you please check what that is and report back?

For the value used by magento/app.cljs I'll update the build in the issue-32-id-cleaning-on-win branch this evening. Then you can update the installation and it will provide the desired information. I'll let you know when the branch is ready.

Thank you!

zaheerbadi commented 5 years ago

$configDirPath path is D:/wamp64/www/mage227/app/etc

Vinai commented 5 years ago

Hi again @zaheerbadi, thank you for the value of $configPath! I've updated the branch with a build that outputs the desired information. To update the build, please run the commands listed above again:

composer remove --dev mage2tv/magento-cache-clean
composer require --dev mage2tv/magento-cache-clean:dev-issue-32-id-cleaning-on-win

The additional info is output always, even if you don't run the watcher with debug log level. That might make it easier to spot the relevant information.

On my system the output looks like this:

% ./bin/cache-clean.js -d "/Users/vinai/Workspace/m2-training" -w                                                                                                                                         Release 0.0.35 sponsored by https://www.mage2.tv

Hot-keys for manual cache cleaning:
[c]onfig [b]lock_html [l]ayout [t]ranslate [f]ull_page [v]iew [a]ll

Hot-keys for cleaning static content areas:
[F]rontend [A]dminhtml

Watcher initialized (Ctrl-C to quit)
Cleaning cache type(s) block_html
Calculated cache ID prefix 707_ from /Volumes/CaseSensitive/Workspace/m2-training/app/etc/

This last line is what I'm after.

Looking forward to your feedback! Thanks!

zaheerbadi commented 5 years ago

@Vinai Here is the output. http://prntscr.com/n6qlm8

It seems still it can't able to find right cache folder.

Vinai commented 5 years ago

Thank you! It still can’t find the right folder because so far I haven’t made any behavioral changes. This was still the debugging phase to see what is going on. But now I know the answer, I know what causes the problem and how to fix it. Thanks again for your help!


Notes:

Magento on Win: `D:/wamp64/www/mage227/app/etc`
Watcher on Win: `D:\wamp64\www\mage227/app/etc`

Magento uses all regular slashes as directory separators, while the node process uses windows backslashes in the basedir path.

Proposed solution: normalize the path to use regular slashes always.

zaheerbadi commented 5 years ago

Ohhk thats good news for us. Hope we have soon error free tool for windows :P

Let me know if you need any help from me.I always happy to help.

Thank you for all your support.

Vinai commented 5 years ago

I've pushed an update to the branch that hopefully fixes the issue. Please update your installation by removing it and installing it again as you did earlier. I'm curious if it now works for you. If it does, I'll merge the change into the main branch and make a new release.

Thanks again for your help.

zaheerbadi commented 5 years ago

Cheers..............! it works

But(may be this is not related to coding issue) There was some issue when composer remove --dev mage2tv/magento-cache-clean composer require --dev mage2tv/magento-cache-clean:dev-issue-32-id-cleaning-on-win command run to install and uninstall.

after removing this module when try to install again using this command it show error like http://prntscr.com/n78p40

So i investigate reason behind this.

it won't delete entire mage2tv directory also when i tried to delete it using windows delete button it ask you don't have permission to delete this so i have to delete it using cmd and then i can able to install new version.

Vinai commented 5 years ago

Thank you for the feedback, @zaheerbadi! The installation issue seems indeed composer related and not specific to mage2tv/magento-cache-clean.

Thanks again for your help in improving windows interoperability! I really have to rely on others to give feedback for that because I don't have access to a windows environment!

I'll keep this issue open until I have rolled the changes into a release.

Vinai commented 5 years ago

Changes are public in release 0.0.37 now.