@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Provide read and overwrite for Lisk counters

Summary:
Ref T6881. This is part 1 of my 35-step plan to support subscriptions that bill monthly.

Expanding the capabilities of counters will let me use them to create a logical clock on time-based event updates, build a daemon on top of that, and eventually get time-based triggers.

Test Plan: Added and executed unit tests.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: chad, epriestley

Maniphest Tasks: T6881

Differential Revision: https://secure.phabricator.com/D11395

+72 -14
-2
src/__phutil_library_map__.php
··· 2231 2231 'PhabricatorProjectUpdateController' => 'applications/project/controller/PhabricatorProjectUpdateController.php', 2232 2232 'PhabricatorProjectViewController' => 'applications/project/controller/PhabricatorProjectViewController.php', 2233 2233 'PhabricatorProjectWatchController' => 'applications/project/controller/PhabricatorProjectWatchController.php', 2234 - 'PhabricatorProjectWikiExplainController' => 'applications/project/controller/PhabricatorProjectWikiExplainController.php', 2235 2234 'PhabricatorProjectsPolicyRule' => 'applications/policy/rule/PhabricatorProjectsPolicyRule.php', 2236 2235 'PhabricatorPygmentSetupCheck' => 'applications/config/check/PhabricatorPygmentSetupCheck.php', 2237 2236 'PhabricatorQuery' => 'infrastructure/query/PhabricatorQuery.php', ··· 5459 5458 'PhabricatorProjectUpdateController' => 'PhabricatorProjectController', 5460 5459 'PhabricatorProjectViewController' => 'PhabricatorProjectController', 5461 5460 'PhabricatorProjectWatchController' => 'PhabricatorProjectController', 5462 - 'PhabricatorProjectWikiExplainController' => 'PhabricatorProjectController', 5463 5461 'PhabricatorProjectsPolicyRule' => 'PhabricatorPolicyRule', 5464 5462 'PhabricatorPygmentSetupCheck' => 'PhabricatorSetupCheck', 5465 5463 'PhabricatorRecaptchaConfigOptions' => 'PhabricatorApplicationConfigOptions',
+55 -2
src/infrastructure/storage/lisk/LiskDAO.php
··· 1173 1173 $id_key = $this->getIDKeyForUse(); 1174 1174 if (empty($data[$id_key])) { 1175 1175 $counter_name = $this->getTableName(); 1176 - $id = self::loadNextCounterID($conn, $counter_name); 1176 + $id = self::loadNextCounterValue($conn, $counter_name); 1177 1177 $this->setID($id); 1178 1178 $data[$id_key] = $id; 1179 1179 } ··· 1688 1688 $this->$name = $value; 1689 1689 } 1690 1690 1691 + 1691 1692 /** 1692 1693 * Increments a named counter and returns the next value. 1693 1694 * ··· 1697 1698 * 1698 1699 * @task util 1699 1700 */ 1700 - public static function loadNextCounterID( 1701 + public static function loadNextCounterValue( 1701 1702 AphrontDatabaseConnection $conn_w, 1702 1703 $counter_name) { 1703 1704 ··· 1719 1720 $counter_name); 1720 1721 1721 1722 return $conn_w->getInsertID(); 1723 + } 1724 + 1725 + 1726 + /** 1727 + * Returns the current value of a named counter. 1728 + * 1729 + * @param AphrontDatabaseConnection Database where the counter resides. 1730 + * @param string Counter name to read. 1731 + * @return int|null Current value, or `null` if the counter does not exist. 1732 + * 1733 + * @task util 1734 + */ 1735 + public static function loadCurrentCounterValue( 1736 + AphrontDatabaseConnection $conn_r, 1737 + $counter_name) { 1738 + 1739 + $row = queryfx_one( 1740 + $conn_r, 1741 + 'SELECT counterValue FROM %T WHERE counterName = %s', 1742 + self::COUNTER_TABLE_NAME, 1743 + $counter_name); 1744 + if (!$row) { 1745 + return null; 1746 + } 1747 + 1748 + return (int)$row['counterValue']; 1749 + } 1750 + 1751 + 1752 + /** 1753 + * Overwrite a named counter, forcing it to a specific value. 1754 + * 1755 + * If the counter does not exist, it is created. 1756 + * 1757 + * @param AphrontDatabaseConnection Database where the counter resides. 1758 + * @param string Counter name to create or overwrite. 1759 + * @return void 1760 + * 1761 + * @task util 1762 + */ 1763 + public static function overwriteCounterValue( 1764 + AphrontDatabaseConnection $conn_w, 1765 + $counter_name, 1766 + $counter_value) { 1767 + 1768 + queryfx( 1769 + $conn_w, 1770 + 'INSERT INTO %T (counterName, counterValue) VALUES (%s, %d) 1771 + ON DUPLICATE KEY UPDATE counterValue = VALUES(counterValue)', 1772 + self::COUNTER_TABLE_NAME, 1773 + $counter_name, 1774 + $counter_value); 1722 1775 } 1723 1776 1724 1777 private function getBinaryColumns() {
+17 -10
src/infrastructure/storage/lisk/__tests__/LiskFixtureTestCase.php
··· 99 99 $conn_w = $obj->establishConnection('w'); 100 100 101 101 // Test that the counter bascially behaves as expected. 102 - $this->assertEqual(1, LiskDAO::loadNextCounterID($conn_w, 'a')); 103 - $this->assertEqual(2, LiskDAO::loadNextCounterID($conn_w, 'a')); 104 - $this->assertEqual(3, LiskDAO::loadNextCounterID($conn_w, 'a')); 102 + $this->assertEqual(1, LiskDAO::loadNextCounterValue($conn_w, 'a')); 103 + $this->assertEqual(2, LiskDAO::loadNextCounterValue($conn_w, 'a')); 104 + $this->assertEqual(3, LiskDAO::loadNextCounterValue($conn_w, 'a')); 105 105 106 106 // This first insert is primarily a test that the previous LAST_INSERT_ID() 107 107 // value does not bleed into the creation of a new counter. 108 - $this->assertEqual(1, LiskDAO::loadNextCounterID($conn_w, 'b')); 109 - $this->assertEqual(2, LiskDAO::loadNextCounterID($conn_w, 'b')); 108 + $this->assertEqual(1, LiskDAO::loadNextCounterValue($conn_w, 'b')); 109 + $this->assertEqual(2, LiskDAO::loadNextCounterValue($conn_w, 'b')); 110 + 111 + // Test alternate access/overwrite methods. 112 + $this->assertEqual(3, LiskDAO::loadCurrentCounterValue($conn_w, 'a')); 113 + 114 + LiskDAO::overwriteCounterValue($conn_w, 'a', 42); 115 + $this->assertEqual(42, LiskDAO::loadCurrentCounterValue($conn_w, 'a')); 116 + $this->assertEqual(43, LiskDAO::loadNextCounterValue($conn_w, 'a')); 110 117 111 118 // These inserts alternate database connections. Since unit tests are 112 119 // transactional by default, we need to break out of them or we'll deadlock ··· 117 124 $conn_1 = $obj->establishConnection('w', $force_new = true); 118 125 $conn_2 = $obj->establishConnection('w', $force_new = true); 119 126 120 - $this->assertEqual(1, LiskDAO::loadNextCounterID($conn_1, 'z')); 121 - $this->assertEqual(2, LiskDAO::loadNextCounterID($conn_2, 'z')); 122 - $this->assertEqual(3, LiskDAO::loadNextCounterID($conn_1, 'z')); 123 - $this->assertEqual(4, LiskDAO::loadNextCounterID($conn_2, 'z')); 124 - $this->assertEqual(5, LiskDAO::loadNextCounterID($conn_1, 'z')); 127 + $this->assertEqual(1, LiskDAO::loadNextCounterValue($conn_1, 'z')); 128 + $this->assertEqual(2, LiskDAO::loadNextCounterValue($conn_2, 'z')); 129 + $this->assertEqual(3, LiskDAO::loadNextCounterValue($conn_1, 'z')); 130 + $this->assertEqual(4, LiskDAO::loadNextCounterValue($conn_2, 'z')); 131 + $this->assertEqual(5, LiskDAO::loadNextCounterValue($conn_1, 'z')); 125 132 126 133 LiskDAO::beginIsolateAllLiskEffectsToTransactions(); 127 134 } catch (Exception $ex) {