Skip to content

Instantly share code, notes, and snippets.

@rkok
Last active October 10, 2023 06:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rkok/69f6f008f9dbca749129e28401b01dfd to your computer and use it in GitHub Desktop.
Save rkok/69f6f008f9dbca749129e28401b01dfd to your computer and use it in GitHub Desktop.
Cleanup InfiniteWP history tables
#!/usr/bin/env bash
#################################################
# For each site in InfiniteWP,
# removes all but the latest history records.
#
# This speeds up InfiniteWP and
# reduces the size of its tables,
# particularly iwp_history_raw_details.
#
# Indended to be run as a daily cronjob.
#################################################
echo "Cleaning up InfiniteWP outdated site history records"
set -x
mysql -N -s infinitewp -e 'delete from iwp_history where historyID not in ( select h.histID from ( select siteID, MAX(historyID) histID from iwp_history GROUP BY siteID ) h )'
mysql -N -s infinitewp -e 'delete from iwp_history_additional_data where historyID not in (select historyID from iwp_history)'
mysql -N -s infinitewp -e 'delete from iwp_history_raw_details where historyID not in (select historyID from iwp_history)'
set +x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment