r49584 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r49583‎ | r49584 | r49585 >
Date:23:29, 16 April 2009
Author:tparscal
Status:deferred
Tags:
Comment:
Added a selective pruning ratio. Removed some old references that aren't needed.
Modified paths:
  • /trunk/extensions/Drafts/Drafts.classes.php (modified) (history)
  • /trunk/extensions/Drafts/Drafts.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Drafts/Drafts.classes.php
@@ -10,6 +10,11 @@
1111
1212 /* Static Functions */
1313
 14+ private static function getDraftAgeCutoff() {
 15+ global $egDraftsLifeSpan;
 16+ return wfTimestamp( TS_UNIX ) - ( $egDraftsLifeSpan * 60 * 60 * 24 );
 17+ }
 18+
1419 /**
1520 * Counts the number of existing drafts for a specific user
1621 * @return Number of drafts which match condition parameters
@@ -17,16 +22,18 @@
1823 * @param integer $userID[optional] ID of user, defaults to current user
1924 */
2025 public static function num(
21 - &$title = null,
 26+ $title = null,
2227 $userID = null
2328 ) {
2429 global $wgUser;
25 - // Removes expired drafts for a more accurate count
26 - self::clean();
2730 // Get database connection
2831 $dbr = wfGetDB( DB_SLAVE );
2932 // Builds where clause
30 - $where = array();
 33+ $where = array(
 34+ 'draft_savetime > ' . $dbr->addQuotes(
 35+ $dbr->timestamp( self::getDraftAgeCutoff() )
 36+ )
 37+ );
3138 // Checks if a specific title was given
3239 if ( $title !== null ) {
3340 // Adds specific title to conditions
@@ -50,19 +57,23 @@
5158 * by $wgDraftsLifeSpan
5259 */
5360 public static function clean() {
54 - global $egDraftsLifeSpan;
55 - // Get database connection
56 - $dbw = wfGetDB( DB_MASTER );
57 - // Sets cuttoff as age longer than $wgDraftsLifeSpan days old
58 - $cutoff = wfTimestamp( TS_UNIX ) - ( $egDraftsLifeSpan * 60 * 60 * 24 );
59 - // Removes expired drafts from database
60 - $dbw->delete( 'drafts',
61 - array(
62 - 'draft_savetime < ' .
63 - $dbw->addQuotes( $dbw->timestamp( $cutoff ) )
64 - ),
65 - __METHOD__
66 - );
 61+ global $egDraftsCleanRatio;
 62+
 63+ // Only perform this action a fraction of the time
 64+ if ( rand( 0, $egDraftsCleanRatio ) == 0 ) {
 65+ // Get database connection
 66+ $dbw = wfGetDB( DB_MASTER );
 67+ // Removes expired drafts from database
 68+ $dbw->delete( 'drafts',
 69+ array(
 70+ 'draft_savetime < ' .
 71+ $dbw->addQuotes(
 72+ $dbw->timestamp( self::getDraftAgeCutoff() )
 73+ )
 74+ ),
 75+ __METHOD__
 76+ );
 77+ }
6778 }
6879
6980 /**
@@ -104,7 +115,11 @@
105116 // Gets database connection
106117 $dbw = wfGetDB( DB_MASTER );
107118 // Builds where clause
108 - $where = array();
 119+ $where = array(
 120+ 'draft_savetime > ' . $dbw->addQuotes(
 121+ $dbw->timestamp( self::getDraftAgeCutoff() )
 122+ )
 123+ );
109124 // Checks if specific title was given
110125 if ( $title !== null ) {
111126 // Gets page id from title
@@ -148,7 +163,7 @@
149164 * @param integer $userID[optional] ID of user, defaults to current user
150165 */
151166 public static function display(
152 - &$title = null,
 167+ $title = null,
153168 $userID = null
154169 ) {
155170 global $wgOut, $wgRequest, $wgUser, $wgLang;
Index: trunk/extensions/Drafts/Drafts.php
@@ -50,6 +50,12 @@
5151 // Days to keep drafts around before automatic deletion
5252 $egDraftsLifeSpan = 30;
5353
 54+// Ratio of times which a list of drafts requested and the list should be pruned
 55+// for expired drafts - expired drafts will not apear in the list even if they
 56+// are not yet pruned, this is just a way to keep the database from filling up
 57+// with old drafts
 58+$egDraftsCleanRatio = 1000;
 59+
5460 // Save and View components
5561 $wgAutoloadClasses['Drafts'] = $dir . 'Drafts.classes.php';
5662 $wgAutoloadClasses['Draft'] = $dir . 'Drafts.classes.php';

Status & tagging log