WordPress.org

Make WordPress Core

Opened 4 weeks ago

Last modified 4 weeks ago

#41699 new defect (bug)

Expired transients are not flushed by cron

Reported by: bor0 Owned by:
Milestone: 4.9 Priority: normal
Severity: normal Version: 4.8.1
Component: Options, Meta APIs Keywords: dev-feedback
Focuses: Cc:

Description

Hi there.

Is there a special reason why we delete expired transients only on get_transient attempt (https://github.com/WordPress/WordPress/blob/master/wp-includes/option.php#L662), but not in cron.php?

I believe https://github.com/WordPress/WordPress/blob/master/wp-admin/includes/upgrade.php#L1748-L1759 belongs in cron.php. Otherwise we're having leftover transients until it's attempted to retrieve them.

I will assume two cases from here:

  • It was done due to performance reasons. In which case there could've been a button in the wp-admin somewhere to flush the expired transients, or allow the users to enable/disable cron deletion through a config param in wp-config.php.
  • It was a bad design decision. In which case we can copy the excerpt from upgrade.php to cron.php somewhere.

In any case, I believe the fix is easy and doesn't have a big impact, while at the same time it allows us to keep the DB from being polluted.

Attachments (1)

41699.diff (725 bytes) - added by Mte90 4 weeks ago.

Download all attachments as: .zip

Change History (6)

#1 @bor0
4 weeks ago

  • Keywords dev-feedback added

This ticket was mentioned in Slack in #core by bor0. View the logs.


4 weeks ago

This ticket was mentioned in Slack in #core by bor0. View the logs.


4 weeks ago

#4 @SergeyBiryukov
4 weeks ago

  • Milestone changed from Awaiting Review to 4.9

@Mte90
4 weeks ago

#5 @Mte90
4 weeks ago

Looking at the code there is already a loop of all the hooks with unschedule (https://github.com/WordPress/WordPress/blob/master/wp-cron.php#L115).
But unschedule is used to remove in the system the scheduled hooks and not cleaning.

Looking at the code in upgrade.php the query is running for a multisite environment but if we are running wp-cron.php we have to act on the cron stuff of the site that is running.

So looking on the code of a famous wordpress plugin for clean the transient (https://plugins.trac.wordpress.org/browser/delete-expired-transients/trunk/includes/class.DelxtransCleaners.php) I made that patch that run the query before the die(); of wp-cron.

Note: See TracTickets for help on using tickets.