-
Notifications
You must be signed in to change notification settings - Fork 147
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
qtranxf_filter_postmeta overwrites metavalues changed during the request #138
Comments
Thank you very much for reporting this. I did changes similar like you suggested and it passed may testing so far. Could you please try the latest https://github.com/qTranslate-Team/qtranslate-x/archive/master.zip and see if you can reproduce the problem again? To save the clicks, I am closing it now, we can still write to closed issue and we may re-open it if needed. |
Sorry John, this doesn't solve it for the WooCommerce stock issue. I think this happens:
|
Does not it clear cache on each update automatically? I did not check that ... How are we going to solve this? Is there a filter in update_meta, which we could employ to clear cache? |
I justed checked what really happens. WP does clear the cache after updating _stock in the database, but right before fetching the updated _stock value another post_meta is fetched (_backorders) and thus the wp_cache is written again. After that _stock is fetched, but since wp_cache_get fetches a value, qTr-X will use the obsolete cached value. There is an action that is called after updating meta: And if metatype is post: So this could be used to invalidate the qTr-X cache somehow I guess ?!?! |
@josk79: thanks a lot for the research. I added 'updated_postmeta' action, but did not test it, have to run now. Could you test it: https://github.com/qTranslate-Team/qtranslate-x/archive/master.zip |
That doesn't work either. Either the qTranslate-X cache of the object has to be removed when the action update_postmeta is called by WP or some other trick must be used (like my hash trick). Some other trick might be saving the qTr-X cache as if it were metadata itself. So instead of storing it as a new cache postmeta_en, why not saving it within the postmeta for example as _qtranx_cache_en. This way it will be atomatically deleted when wp_cache_delete is called. Might that work? If I have time and concentration, I can try it tomorrow, but would like your opinion first. |
I am puzzled. I tested it and could not fail it. Function 'qtranxf_updated_postmeta' deletes QTX cache on update of meta and next time 'get_' is called, the cache has to be re-created. I do not see a way around. Could you give me a sequence of PHP lines I can execute which show the problem? There is function qtranxf_test_meta_cache in https://github.com/qTranslate-Team/qtranslate-x/blob/master/dev/qtx-tests.php, which I used to test it. Could you modify it or create a similar function so that it would show the problem? |
Do you have an environment with WooCommerce by any change? Then it's easy to reproduce, simply by placing an order. update_post_meta is not called by WooCommerce when changes the stock. This is the code responsible for stock-changing:
Note that during check_stock_status(), the _stock is reread. You reckon that Woothemes should call updated_postmeta after the unset? |
How exactly does it get re-read? Don't they use get_post_meta? Otherwise it should still work. |
I made an environment, how can I send you credentials (privately?) |
Please note that this problem is not limited to Woocommerce only, it affects other plugins too, particularly http://www.github.com/Teplitsa/Leyka |
Thank you. Please, use qtranslateteam at g m ail d c om. |
I Sent you the credentials. In WP-Admin - WooCommerce - Orders you'll find 2 orders: Stock is changed in woocommerce/includes/abstracts/abstract-wc-product.php:223 This function executes wp_cache_delete, which should invalidate the qTr cache. But as you can see check_stock_status is called which retrieves two metas (indirectly with get_post_meta, (see __get): first it retrieves _backorders, this will cause the postmeta to be cached by wp |
@johnclause yes i use the latest version |
Thank you, @josk79, the problem was that I forgot to change function All, please, test the latest version https://github.com/qTranslate-Team/qtranslate-x/archive/master.zip and make sure to delete previous version of plugin before uploading the new one, as the version number has not been changed, it is still 3.2.9.9.6. Could you confirm with your testing if this is ok now? Thank you. |
Lookin' good! WooCommerce stock management now works fine. Thanks! |
Unfortunately, the problem still persists wnen using both qtranslate-x and Leyka plugin. I've dropped you an email with the problem details and some screenshots. |
Thank you very much @Axumata for providing the testing environment. Indeed, there was one more problem, different and unrelated to the topic of this issue, but since it should be solved by now, we will not open a new issue. I had to add a couple more lines of code in function qtranxf_filter_postmeta with an extensive explanation:
Please, @Axumata & @josk79, could you both re-test again the latest version from GitHub: https://github.com/qTranslate-Team/qtranslate-x/archive/master.zip. For @Axumata, I already uploaded the new version to his testing site. This time, I increased the version conter and even made another alpha release: https://github.com/qTranslate-Team/qtranslate-x/releases/tag/3.2.9.9.7 This one will probably go as 3.3, unless sombody reports something else again. |
Just tested on two sites. It's still working! |
Thank you! I guess we can close this issue now, we can still write to closed issue and we may re-open it if needed. |
@johnclause thanks for the fix bug. 3.2.9.9.7 working fine! |
qtranxf_filter_postmeta seems to use it's only little caching for translated metadata. This works fine as long as the original metadata isn't changed during the request.
An example: in WooCommerce when an order is placed, the stock-level for products is changed. After doing so, some checks are performed, for example to mark an item as 'out-of-stock'. But since the q-X 3.2.3 qtranxf_filter_postmeta was added, this doesn't work as it should.
A solution could be adding a hash of the objects' metadata to the cache key:
OLD (qtranslate-frontend.php version 3.2.9.9.3):
SUGGESTION:
...and at the end of the function don't execute
wp_cache_add
if $cache_key_lang is not set;I don't know if this is the best solution, what do you think?
Is it actually a good/safe idea to use the cache trick that is used by qtranxf_filter_postmeta?
This support thread is related: https://wordpress.org/support/topic/filter-qtranxf_filter_postmeta-issue
The text was updated successfully, but these errors were encountered: