Skip to content

Fix cleanup batching + reduce DB load on high-traffic sites#10

Open
gsusI wants to merge 3 commits intowp-media:mainfrom
gsusI:fix/cleanup-cron-and-db-load
Open

Fix cleanup batching + reduce DB load on high-traffic sites#10
gsusI wants to merge 3 commits intowp-media:mainfrom
gsusI:fix/cleanup-cron-and-db-load

Conversation

@gsusI
Copy link

@gsusI gsusI commented Feb 10, 2026

Fixes #9.

Changes

  • Fix cleanup threshold calculation to be relative to "now" (was hard-coded), so old rows are actually purged.
  • Re-enable iterative batch cleanup scheduling until the table is within the retention window.
  • Remove cron-time output (no echo).
  • Bound rsp_get_most_visited() aggregation to the same retention window (RSP_CLEANUP_THREASHOLD_TIME) to keep the query bounded if cron is delayed.
  • Use a single-statement INSERT ... ON DUPLICATE KEY UPDATE for visit recording to reduce DB queries per page view and keep updates atomic.
  • Add an index on last_visit in the table schema to speed cleanup / range queries (via dbDelta on activation).
  • Add an admin notice + CTA to add the last_visit index on demand (so high-traffic sites can run it off-peak).
  • Bump package version to 1.1.1.

Notes

  • The DB update notice is shown on the Plugins screen and the plugin settings page until an index on last_visit exists.
  • The CTA runs an ALTER TABLE ... ADD INDEX ... which can take time and lock writes on very large tables.

Related: #8

@gsusI gsusI marked this pull request as ready for review February 10, 2026 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: cleanup threshold uses fixed DateTime and batch rescheduling is disabled (table grows indefinitely)

1 participant