Make WordPress Core


Ignore:
Timestamp:
10/18/2013 07:47:44 AM (13 years ago)
Author:
nacin
Message:

Delete expired transients on database upgrades.

Reverts [25416], which had all transients being cleared. This leaves much to be desired, but we don't want a core update to be blamed for breaking a site that incorrectly assumes transients aren't transient.

props dartiss, pento.
fixes #20316.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/schema.php

    r25448 r25838  
    547547        // delete obsolete magpie stuff
    548548        $wpdb->query("DELETE FROM $wpdb->options WHERE option_name REGEXP '^rss_[0-9a-f]{32}(_ts)?$'");
    549         // clear transient data
    550         $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '\_transient\_%' OR option_name LIKE '\_site\_transient\_%'" );
     549
     550        // Deletes all expired transients.
     551        // The multi-table delete syntax is used to delete the transient record from table a,
     552        // and the corresponding transient_timeout record from table b.
     553        $time = time();
     554        $wpdb->query("DELETE a, b FROM $wpdb->options a, $wpdb->options b WHERE
     555                a.option_name LIKE '\_transient\_%' AND
     556                a.option_name NOT LIKE '\_transient\_timeout\_%' AND
     557                b.option_name = CONCAT( '_transient_timeout_', SUBSTRING( a.option_name, 12 ) )
     558                AND b.option_value < $time");
     559
     560        if ( is_main_site() && is_main_network() ) {
     561                $wpdb->query("DELETE a, b FROM $wpdb->options a, $wpdb->options b WHERE
     562                        a.option_name LIKE '\_site\_transient\_%' AND
     563                        a.option_name NOT LIKE '\_site\_transient\_timeout\_%' AND
     564                        b.option_name = CONCAT( '_site_transient_timeout_', SUBSTRING( a.option_name, 17 ) )
     565                        AND b.option_value < $time");
     566    }
    551567}
    552568
Note: See TracChangeset for help on using the changeset viewer.