Page MenuHomePhabricator

D11395.diff
No OneTemporary

D11395.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -2231,7 +2231,6 @@
'PhabricatorProjectUpdateController' => 'applications/project/controller/PhabricatorProjectUpdateController.php',
'PhabricatorProjectViewController' => 'applications/project/controller/PhabricatorProjectViewController.php',
'PhabricatorProjectWatchController' => 'applications/project/controller/PhabricatorProjectWatchController.php',
- 'PhabricatorProjectWikiExplainController' => 'applications/project/controller/PhabricatorProjectWikiExplainController.php',
'PhabricatorProjectsPolicyRule' => 'applications/policy/rule/PhabricatorProjectsPolicyRule.php',
'PhabricatorPygmentSetupCheck' => 'applications/config/check/PhabricatorPygmentSetupCheck.php',
'PhabricatorQuery' => 'infrastructure/query/PhabricatorQuery.php',
@@ -5459,7 +5458,6 @@
'PhabricatorProjectUpdateController' => 'PhabricatorProjectController',
'PhabricatorProjectViewController' => 'PhabricatorProjectController',
'PhabricatorProjectWatchController' => 'PhabricatorProjectController',
- 'PhabricatorProjectWikiExplainController' => 'PhabricatorProjectController',
'PhabricatorProjectsPolicyRule' => 'PhabricatorPolicyRule',
'PhabricatorPygmentSetupCheck' => 'PhabricatorSetupCheck',
'PhabricatorRecaptchaConfigOptions' => 'PhabricatorApplicationConfigOptions',
diff --git a/src/infrastructure/storage/lisk/LiskDAO.php b/src/infrastructure/storage/lisk/LiskDAO.php
--- a/src/infrastructure/storage/lisk/LiskDAO.php
+++ b/src/infrastructure/storage/lisk/LiskDAO.php
@@ -1173,7 +1173,7 @@
$id_key = $this->getIDKeyForUse();
if (empty($data[$id_key])) {
$counter_name = $this->getTableName();
- $id = self::loadNextCounterID($conn, $counter_name);
+ $id = self::loadNextCounterValue($conn, $counter_name);
$this->setID($id);
$data[$id_key] = $id;
}
@@ -1688,6 +1688,7 @@
$this->$name = $value;
}
+
/**
* Increments a named counter and returns the next value.
*
@@ -1697,7 +1698,7 @@
*
* @task util
*/
- public static function loadNextCounterID(
+ public static function loadNextCounterValue(
AphrontDatabaseConnection $conn_w,
$counter_name) {
@@ -1721,6 +1722,58 @@
return $conn_w->getInsertID();
}
+
+ /**
+ * Returns the current value of a named counter.
+ *
+ * @param AphrontDatabaseConnection Database where the counter resides.
+ * @param string Counter name to read.
+ * @return int|null Current value, or `null` if the counter does not exist.
+ *
+ * @task util
+ */
+ public static function loadCurrentCounterValue(
+ AphrontDatabaseConnection $conn_r,
+ $counter_name) {
+
+ $row = queryfx_one(
+ $conn_r,
+ 'SELECT counterValue FROM %T WHERE counterName = %s',
+ self::COUNTER_TABLE_NAME,
+ $counter_name);
+ if (!$row) {
+ return null;
+ }
+
+ return (int)$row['counterValue'];
+ }
+
+
+ /**
+ * Overwrite a named counter, forcing it to a specific value.
+ *
+ * If the counter does not exist, it is created.
+ *
+ * @param AphrontDatabaseConnection Database where the counter resides.
+ * @param string Counter name to create or overwrite.
+ * @return void
+ *
+ * @task util
+ */
+ public static function overwriteCounterValue(
+ AphrontDatabaseConnection $conn_w,
+ $counter_name,
+ $counter_value) {
+
+ queryfx(
+ $conn_w,
+ 'INSERT INTO %T (counterName, counterValue) VALUES (%s, %d)
+ ON DUPLICATE KEY UPDATE counterValue = VALUES(counterValue)',
+ self::COUNTER_TABLE_NAME,
+ $counter_name,
+ $counter_value);
+ }
+
private function getBinaryColumns() {
return $this->getConfigOption(self::CONFIG_BINARY);
}
diff --git a/src/infrastructure/storage/lisk/__tests__/LiskFixtureTestCase.php b/src/infrastructure/storage/lisk/__tests__/LiskFixtureTestCase.php
--- a/src/infrastructure/storage/lisk/__tests__/LiskFixtureTestCase.php
+++ b/src/infrastructure/storage/lisk/__tests__/LiskFixtureTestCase.php
@@ -99,14 +99,21 @@
$conn_w = $obj->establishConnection('w');
// Test that the counter bascially behaves as expected.
- $this->assertEqual(1, LiskDAO::loadNextCounterID($conn_w, 'a'));
- $this->assertEqual(2, LiskDAO::loadNextCounterID($conn_w, 'a'));
- $this->assertEqual(3, LiskDAO::loadNextCounterID($conn_w, 'a'));
+ $this->assertEqual(1, LiskDAO::loadNextCounterValue($conn_w, 'a'));
+ $this->assertEqual(2, LiskDAO::loadNextCounterValue($conn_w, 'a'));
+ $this->assertEqual(3, LiskDAO::loadNextCounterValue($conn_w, 'a'));
// This first insert is primarily a test that the previous LAST_INSERT_ID()
// value does not bleed into the creation of a new counter.
- $this->assertEqual(1, LiskDAO::loadNextCounterID($conn_w, 'b'));
- $this->assertEqual(2, LiskDAO::loadNextCounterID($conn_w, 'b'));
+ $this->assertEqual(1, LiskDAO::loadNextCounterValue($conn_w, 'b'));
+ $this->assertEqual(2, LiskDAO::loadNextCounterValue($conn_w, 'b'));
+
+ // Test alternate access/overwrite methods.
+ $this->assertEqual(3, LiskDAO::loadCurrentCounterValue($conn_w, 'a'));
+
+ LiskDAO::overwriteCounterValue($conn_w, 'a', 42);
+ $this->assertEqual(42, LiskDAO::loadCurrentCounterValue($conn_w, 'a'));
+ $this->assertEqual(43, LiskDAO::loadNextCounterValue($conn_w, 'a'));
// These inserts alternate database connections. Since unit tests are
// transactional by default, we need to break out of them or we'll deadlock
@@ -117,11 +124,11 @@
$conn_1 = $obj->establishConnection('w', $force_new = true);
$conn_2 = $obj->establishConnection('w', $force_new = true);
- $this->assertEqual(1, LiskDAO::loadNextCounterID($conn_1, 'z'));
- $this->assertEqual(2, LiskDAO::loadNextCounterID($conn_2, 'z'));
- $this->assertEqual(3, LiskDAO::loadNextCounterID($conn_1, 'z'));
- $this->assertEqual(4, LiskDAO::loadNextCounterID($conn_2, 'z'));
- $this->assertEqual(5, LiskDAO::loadNextCounterID($conn_1, 'z'));
+ $this->assertEqual(1, LiskDAO::loadNextCounterValue($conn_1, 'z'));
+ $this->assertEqual(2, LiskDAO::loadNextCounterValue($conn_2, 'z'));
+ $this->assertEqual(3, LiskDAO::loadNextCounterValue($conn_1, 'z'));
+ $this->assertEqual(4, LiskDAO::loadNextCounterValue($conn_2, 'z'));
+ $this->assertEqual(5, LiskDAO::loadNextCounterValue($conn_1, 'z'));
LiskDAO::beginIsolateAllLiskEffectsToTransactions();
} catch (Exception $ex) {

File Metadata

Mime Type
text/plain
Expires
Wed, Nov 6, 5:25 PM (6 d, 9 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6742650
Default Alt Text
D11395.diff (6 KB)

Event Timeline