Hoo man has uploaded a new change for review.
https://gerrit.wikimedia.org/r/189511
Change subject: Only delete up to 25k rows in pruneChanges
......................................................................
Only delete up to 25k rows in pruneChanges
Untested.
Bug: T88981
Change-Id: I7f375e4e9f8e82734f0535ddec3d0fd1b3cb1957
---
M repo/maintenance/pruneChanges.php
1 file changed, 34 insertions(+), 3 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/11/189511/1
diff --git a/repo/maintenance/pruneChanges.php
b/repo/maintenance/pruneChanges.php
index 1d56aa6..9685935 100644
--- a/repo/maintenance/pruneChanges.php
+++ b/repo/maintenance/pruneChanges.php
@@ -31,6 +31,11 @@
*/
private $ignoreDispatch = false;
+ /**
+ * @var int The amount of rows to delete at once.
+ */
+ private $pruneLimit = 0;
+
public function __construct() {
parent::__construct();
$this->mDescription = "Prune the Wikibase changes table to a
maximum number of entries";
@@ -40,6 +45,8 @@
$this->addOption( 'keep-hours', 'Keep changes at least N
hours.', false, true, 'h' );
$this->addOption( 'keep-minutes', 'Keep changes at least N
minutes.', false, true, 'm' );
$this->addOption( 'grace-minutes', 'Keep changes at least N
more minutes after they have been dispatched.', false, true, 'g' );
+
+ $this->addOption( 'limit', 'Only prune up to N rows at once.',
false, true, 'l' );
$this->addOption( 'force', 'Run regardless of whether the PID
file says it is running already.',
false, false, 'f' );
@@ -83,7 +90,10 @@
$this->graceSeconds = 1 * 60 * 60;
}
+ $this->pruneLimit = intval( $this->getOption( 'limit', 25000 )
);
+
$until = $this->getCutoffTimestamp();
+ $until = $this->limitDeletions( $until );
$this->output( date( 'H:i:s' ) . " pruning entries older than "
. wfTimestamp( TS_ISO_8601, $until ) . "\n" );
@@ -102,8 +112,8 @@
$until = time() - $this->keepSeconds;
if ( !$this->ignoreDispatch ) {
- $dbw = wfGetDB( DB_MASTER );
- $row = $dbw->selectRow(
+ $dbr = wfGetDB( DB_SLAVE );
+ $row = $dbr->selectRow(
array ( 'wb_changes_dispatch', 'wb_changes' ),
'min(change_time) as timestamp',
array(
@@ -124,6 +134,27 @@
}
/**
+ * @param int $until
+ *
+ * @return int
+ */
+ private function limitDeletions( $until ) {
+ $dbr = wfGetDB( DB_SLAVE );
+ $changeTime = $dbr->selectField(
+ 'wb_changes',
+ 'change_time',
+ array( 'change_time < ' . $dbr->addQuotes( wfTimestamp(
TS_MW, $until ) ) ),
+ __METHOD__,
+ array(
+ 'OFFSET' => $this->pruneLimit,
+ 'ORDER BY' => 'change_time ASC',
+ )
+ );
+
+ return $changeTime ? intval( $changeTime ) : $until;
+ }
+
+ /**
* Prunes all changes older than $until from the changes table.
*
* @param int $until
@@ -135,7 +166,7 @@
$dbw->delete(
'wb_changes',
- array( "change_time < " . $dbw->addQuotes( wfTimestamp(
TS_MW, $until ) ) ),
+ array( 'change_time < ' . $dbw->addQuotes( wfTimestamp(
TS_MW, $until ) ) ),
__METHOD__
);
--
To view, visit https://gerrit.wikimedia.org/r/189511
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I7f375e4e9f8e82734f0535ddec3d0fd1b3cb1957
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Hoo man <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits