Skip Navigation

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 8 replies, has 2 voices.

Last updated by Christopher Amirian 4 months ago.

Assisted by: Christopher Amirian.

Author Posts
July 28, 2024 at 10:55 am #16011932

witoldW

Background of the issue:
Hello,
I've had huge performance issues with my website and I finally uncovered the culprit. It turned out that for a db of 5k woocommerce products in 3 languages = 15k posts, I actually had nearly half a milion posts in the database with all the corresponding wp_postmeta (almost 3M records).

Upon further inspection, it turned out that nearly all of the posts are of type attachment, that they come from WPML duplicating records for translating media metadata and that while turning WPML on and off several times (including the support tickets here) last year, when I was setting it up initially, I duplicated media meta several times, which turned into this exponential cascade of db records.

Steps I've already taken:
0. Searched WPML support forum and found a lot of similar issues.
1. Reconfigured WPML to never translate media, but this doesn't work retroactively.
2. Run media cleaner, but this was taking hours and returned a lot of unspecified "error server responses". This wasn't much help.
3. Run different SELECT queries on the db to asses the situation. In the end, I've decided to do something drastic:
DELETE post, meta
FROM wp_posts post
INNER JOIN wp_postmeta meta ON post.ID = meta.post_id
WHERE post.post_name REGEXP '^.+-[3-9]+$' AND post.post_type = 'attachment'

You might ask, why 3 and not 1 in the regex. Here lies the current problem I need help with. This cleaned up 400 out of 440k of my wp_posts and most of wp_postmeta. My website performance is mostly fixed, but the cleanup is not complete yet.

Link to a page where the issue can be seen: hidden link

Symptoms:
Expected behavior: After setting WPML to never translate media, _thumbnail_id meta from translated product posts gets ignored and translated products always get their base language image file.

Actual behavior: The translated products now have a broken link to the media file, whose corresponding wp_post doesn't exist. Moreover, deleting the _thumbnail_id meta from the translated product still doesn't help - what happens instead is that the default woocommerce product placeholder image gets shown.

Questions:
My goal: wp_posts should contain only 3 * 5k records for the products in 3 languages + 1 * 5k for untranslated media attachment records + 1k of unrelated records (menus, etc). No media should be translated and all translated products should display the media file from the base translation.

Please advise on the best course of action.

Best Regards,
Jaroslaw Watroba

July 28, 2024 at 11:02 am #16011938

Christopher Amirian
Supporter

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

Hi there,

Please set the next reply as private to provide the login information of the website copy that has the performance issue before the usage of queries on the database.

I also need permission that we might be able to copy that to our server for further investigation or do changes on the current copy that might break the website so, we need a copy of the website that we can freely work on.

Thanks.

July 29, 2024 at 4:21 pm #16017228

Christopher Amirian
Supporter

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

Hi there,

Thank you for the login information. The Database amount is huge and I am stuck in the process of copying it to report.

But I am working on this and will get back to you as soon as I find a way

July 29, 2024 at 4:27 pm #16017254

Christopher Amirian
Supporter

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

For now I asked some basic questions from the second tier to see if they can provide some general solutions regarding the duplicate entries that I can apply on the current website without copying it.

Waiting fro their reply....

July 30, 2024 at 3:50 pm #16021356

Christopher Amirian
Supporter

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

Hi there,

Would you please use this plugin to identify the duplicated entries and remove them?

https://wordpress.org/plugins/media-deduper/

Thanks.

July 30, 2024 at 6:46 pm #16022001

witoldW

I've installed and run the plugin on the staging site. It found 200k duplicates, but there is no bulk way to remove them. Also, there should be closer to 400k as mentioned previously.

I've said previously I tried media deduplicator. This problem was created by your plugin not cleaning up after itself properly and it should be easy for you to get me the SQL to fix this.

This is a very serious issue right now, please treat me seriously.

August 1, 2024 at 6:14 pm #16031074

witoldW

Hello, is any progress being made?

August 2, 2024 at 5:51 pm #16034498

witoldW

delete post, meta from wp_posts post
left join wp_postmeta meta on meta.post_id = post.ID
where post.post_type = 'attachment'
and post.ID > 16806
and post.ID not in (select * from (SELECT ID from wp_posts post inner join wp_postmeta meta on meta.meta_key = '_thumbnail_id' and meta.meta_value = post.ID) r)

Thank you. My business would go bankrupt before you fixed it. I leave it here for posterity though as many other people face this problem too. I used post.ID filter bc there are no duplicated posts before this ID. In this way I saved all media files that aren't product images.

USE THIS QUERY FOR INSPIRATION, BUT MAKE SURE YOU UNDERSTAND WHAT YOU'RE DOING FIRST! ALWAYS HAVE A BACKUP!

August 5, 2024 at 8:19 am #16037936

Christopher Amirian
Supporter

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

Hi there,

Thank you for the solution that you shared. I also need to add that manipulating database with queries need a complete backup of the website before anyone trying such solutions.

Thanks.