PTI - Data Clean Up
Portland tractor imports products nightly to keep inventory up to date. This process also includes importing the associated image files.
The process to import these is through wp_imports. The process to import the images does not update existing records, rather it will orphan the previously imported records, which causes the database to grow and eventually impacts performance.
To maintain this, the following scripts should be run.
This script clears out the metadata for the orphaned records:
DELETE wp_postmeta
FROM wp_postmeta
JOIN (
SELECT wp_posts.ID
FROM wp_posts
WHERE wp_posts.post_type = 'attachment'
AND wp_posts.post_parent = 0
AND wp_posts.post_author = 77777
LIMIT 500000
) p ON wp_postmeta.post_id = p.ID;
This script clears out the orphaned records:
Delete from wp_posts where post_type = 'attachment' and post_parent = 0 and post_author = 77777
This will show the different post types in the wp_posts table:
select count(*) as postCount, post_type from wp_posts group by post_type;