From afdc8b34d837d93e360a3c17a7d3f8f1aa1b1e73 Mon Sep 17 00:00:00 2001 From: Ian Baker Date: Tue, 10 Jan 2012 23:42:03 +0000 Subject: [PATCH] Updated to use correct cross-db timestamps and date functions Added to SQLite updater --- includes/ConcurrencyCheck.php | 16 ++++++------ includes/installer/SqliteUpdater.php | 1 + .../archives/patch-concurrencycheck.sql | 25 +++++++++++++++++++ 3 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 maintenance/sqlite/archives/patch-concurrencycheck.sql diff --git a/includes/ConcurrencyCheck.php b/includes/ConcurrencyCheck.php index 7c20a21aee..66b12599d9 100644 --- a/includes/ConcurrencyCheck.php +++ b/includes/ConcurrencyCheck.php @@ -80,7 +80,7 @@ class ConcurrencyCheck { 'cc_resource_type' => $this->resourceType, 'cc_record' => $record, 'cc_user' => $userId, - 'cc_expiration' => time() + $this->expirationTime, + 'cc_expiration' => wfTimestamp( TS_MW, time() + $this->expirationTime ), ), __METHOD__, array( 'IGNORE' ) @@ -108,11 +108,11 @@ class ConcurrencyCheck { ); // not checked out by current user, checkout is unexpired, override is unset - if( ! ( $override || $row->cc_user == $userId || $row->cc_expiration <= time() ) ) { + if( ! ( $override || $row->cc_user == $userId || wfTimestamp( TS_UNIX, $row->cc_expiration ) <= time() ) ) { // this was a cache miss. populate the cache with data from the db. // cache is set to expire at the same time as the checkout, since it'll become invalid then anyway. // inside this transaction, a row-level lock is established which ensures cache concurrency - $memc->set( $cacheKey, array( 'userId' => $row->cc_user, 'expiration' => $row->cc_expiration ), $row->cc_expiration - time() ); + $memc->set( $cacheKey, array( 'userId' => $row->cc_user, 'expiration' => $row->cc_expiration ), wfTimestamp( TS_UNIX, $row->cc_expiration ) - time() ); $dbw->rollback(); return false; } @@ -127,7 +127,7 @@ class ConcurrencyCheck { 'cc_resource_type' => $this->resourceType, 'cc_record' => $record, 'cc_user' => $userId, - 'cc_expiration' => $expiration, + 'cc_expiration' => wfTimestamp( TS_MW, $expiration ), ), __METHOD__ ); @@ -187,7 +187,7 @@ class ConcurrencyCheck { 'concurrencycheck', array( '*' ), array( - 'cc_expiration <= ' . $now, + 'cc_expiration <= ' . $dbw->addQuotes( wfTimestamp( TS_MW, $now ) ), ), __METHOD__, array() @@ -203,7 +203,7 @@ class ConcurrencyCheck { $dbw->delete( 'concurrencycheck', array( - 'cc_expiration <= ' . $now, + 'cc_expiration <= ' . $dbw->addQuotes( wfTimestamp( TS_MW, $now ) ), ), __METHOD__, array() @@ -238,7 +238,7 @@ class ConcurrencyCheck { 'cc_resource_type' => $this->resourceType, 'cc_record' => $key, 'cc_user' => $cached['userId'], - 'cc_expiration' => $cached['expiration'], + 'cc_expiration' => wfTimestamp( TS_MW, $cached['expiration'] ), 'cache' => 'cached', ); } else { @@ -259,7 +259,7 @@ class ConcurrencyCheck { array( 'cc_resource_type' => $this->resourceType, 'cc_record IN (' . implode( ',', $toSelect ) . ')', - 'cc_expiration > unix_timestamp(now())' + 'cc_expiration > ' . $dbw->addQuotes( wfTimestamp( TS_MW ) ), ), __METHOD__, array() diff --git a/includes/installer/SqliteUpdater.php b/includes/installer/SqliteUpdater.php index fdb64378cd..e89e382730 100644 --- a/includes/installer/SqliteUpdater.php +++ b/includes/installer/SqliteUpdater.php @@ -71,6 +71,7 @@ class SqliteUpdater extends DatabaseUpdater { array( 'modifyField', 'user', 'ug_group', 'patch-ug_group-length-increase.sql' ), array( 'addField', 'uploadstash', 'us_chunk_inx', 'patch-uploadstash_chunk.sql' ), array( 'addfield', 'job', 'job_timestamp', 'patch-jobs-add-timestamp.sql' ), + array( 'addTable', 'concurrencycheck', 'patch-concurrencycheck.sql'), ); } diff --git a/maintenance/sqlite/archives/patch-concurrencycheck.sql b/maintenance/sqlite/archives/patch-concurrencycheck.sql new file mode 100644 index 0000000000..f76b923541 --- /dev/null +++ b/maintenance/sqlite/archives/patch-concurrencycheck.sql @@ -0,0 +1,25 @@ +-- +-- Store atomic locking information for web resources, to permit +-- UI that warns users when concurrently editing things that aren't +-- concurrently editable. +-- +CREATE TABLE /*_*/concurrencycheck ( + -- a string describing the resource or application being checked out. + cc_resource_type varchar(255) NOT NULL, + + -- the (numeric) ID of the record that's being checked out. + cc_record int unsigned NOT NULL, + + -- the user who has control of the resource + cc_user int unsigned NOT NULL, + + -- the date/time on which this record expires + cc_expiration varbinary(14) not null + +) /*$wgDBTableOptions*/; +-- composite pk. +CREATE UNIQUE INDEX /*i*/cc_resource_record ON /*_*/concurrencycheck (cc_resource_type, cc_record); +-- sometimes there's a delete based on userid. +CREATE INDEX /*i*/cc_user ON /*_*/concurrencycheck (cc_user); +-- sometimes there's a delete based on expiration +CREATE INDEX /*i*/cc_expiration ON /*_*/concurrencycheck (cc_expiration); -- 2.20.1