@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.

Remove partial objects from Lisk

Summary:
Ref T4420. This was a performance hack introduced long ago to make typeaheads for users a little cheaper. The idea was that you could load some of an object's columns and skip other ones.

We now always load users on demand, so the cost of loading the whole objects is very small. No other use cases ever arose for this, and it seems unlikely that they will in the future. Remove it all.

Test Plan:
- Grepped for `CONFIG_PARTIAL_OBJECTS`.
- Grepped for `dirtyFields`.
- Grepped for `missingFields`.
- Grepped for `resetDirtyFields`.
- Grepped for `loadColumns`.
- Grepped for `loadColumnsWhere`.
- Grepped for `loadRawDataWhere`.
- Loaded and saved some lisk objects.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T4420

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

+3 -112
-1
src/applications/people/storage/PhabricatorUser.php
··· 113 113 public function getConfiguration() { 114 114 return array( 115 115 self::CONFIG_AUX_PHID => true, 116 - self::CONFIG_PARTIAL_OBJECTS => true, 117 116 ) + parent::getConfiguration(); 118 117 } 119 118
+3 -111
src/infrastructure/storage/lisk/LiskDAO.php
··· 168 168 const CONFIG_TIMESTAMPS = 'timestamps'; 169 169 const CONFIG_AUX_PHID = 'auxiliary-phid'; 170 170 const CONFIG_SERIALIZATION = 'col-serialization'; 171 - const CONFIG_PARTIAL_OBJECTS = 'partial-objects'; 172 171 const CONFIG_BINARY = 'binary'; 173 172 174 173 const SERIALIZATION_NONE = 'id'; ··· 181 180 182 181 const COUNTER_TABLE_NAME = 'lisk_counter'; 183 182 184 - private $dirtyFields = array(); 185 - private $missingFields = array(); 186 183 private static $processIsolationLevel = 0; 187 184 private static $transactionIsolationLevel = 0; 188 185 ··· 206 203 $id_key = $this->getIDKey(); 207 204 if ($id_key) { 208 205 $this->$id_key = null; 209 - } 210 - 211 - if ($this->getConfigOption(self::CONFIG_PARTIAL_OBJECTS)) { 212 - $this->resetDirtyFields(); 213 206 } 214 207 } 215 208 ··· 345 338 * This will cause Lisk to JSON-serialize the 'complex' field before it is 346 339 * written, and unserialize it when it is read. 347 340 * 348 - * CONFIG_PARTIAL_OBJECTS 349 - * Sometimes, it is useful to load only some fields of an object (such as 350 - * when you are loading all objects of a class, but only care about a few 351 - * fields). Turning on this option (by setting it to a truthy value) allows 352 - * users of the class to create/use partial objects, but it comes with some 353 - * side effects: your class cannot override the setters and getters provided 354 - * by Lisk (use readField and writeField instead), and you should not 355 - * directly access or assign protected members of your class (use the getters 356 - * and setters). 357 - * 358 341 * CONFIG_BINARY 359 342 * You can optionally provide a map of columns to a flag indicating that 360 343 * they store binary data. These columns will not raise an error when ··· 368 351 return array( 369 352 self::CONFIG_IDS => self::IDS_AUTOINCREMENT, 370 353 self::CONFIG_TIMESTAMPS => true, 371 - self::CONFIG_PARTIAL_OBJECTS => false, 372 354 ); 373 355 } 374 356 ··· 435 417 return $this->loadAllWhere('1 = 1'); 436 418 } 437 419 438 - /** 439 - * Loads all objects, but only fetches the specified columns. 440 - * 441 - * @param array Array of canonical column names as strings 442 - * @return dict Dictionary of all objects, keyed by ID. 443 - * 444 - * @task load 445 - */ 446 - public function loadColumns(array $columns) { 447 - return $this->loadColumnsWhere($columns, '1 = 1'); 448 - } 449 - 450 420 451 421 /** 452 422 * Load all objects which match a WHERE clause. You provide everything after ··· 464 434 */ 465 435 public function loadAllWhere($pattern /* , $arg, $arg, $arg ... */) { 466 436 $args = func_get_args(); 467 - array_unshift($args, null); 468 - $data = call_user_func_array( 469 - array($this, 'loadRawDataWhere'), 470 - $args); 471 - return $this->loadAllFromArray($data); 472 - } 473 - 474 - /** 475 - * Loads selected columns from objects that match a WHERE clause. You must 476 - * provide everything after the WHERE. See loadAllWhere(). 477 - * 478 - * @param array List of column names. 479 - * @param string queryfx()-style SQL WHERE clause. 480 - * @param ... Zero or more conversions. 481 - * @return dict Dictionary of matching objecks, keyed by ID. 482 - * 483 - * @task load 484 - */ 485 - public function loadColumnsWhere(array $columns, $pattern /* , $args... */) { 486 - if (!$this->getConfigOption(self::CONFIG_PARTIAL_OBJECTS)) { 487 - throw new BadMethodCallException( 488 - 'This class does not support partial objects.'); 489 - } 490 - $args = func_get_args(); 491 437 $data = call_user_func_array( 492 438 array($this, 'loadRawDataWhere'), 493 439 $args); ··· 509 455 */ 510 456 public function loadOneWhere($pattern /* , $arg, $arg, $arg ... */) { 511 457 $args = func_get_args(); 512 - array_unshift($args, null); 513 458 $data = call_user_func_array( 514 459 array($this, 'loadRawDataWhere'), 515 460 $args); ··· 528 473 } 529 474 530 475 531 - protected function loadRawDataWhere($columns, $pattern /* , $args... */) { 476 + protected function loadRawDataWhere($pattern /* , $args... */) { 532 477 $connection = $this->establishConnection('r'); 533 478 534 479 $lock_clause = ''; ··· 539 484 } 540 485 541 486 $args = func_get_args(); 542 - $args = array_slice($args, 2); 543 - 544 - if (!$columns) { 545 - $column = '*'; 546 - } else { 547 - $column = '%LC'; 548 - $columns[] = $this->getIDKey(); 487 + $args = array_slice($args, 1); 549 488 550 - $properties = $this->getProperties(); 551 - $this->missingFields = array_diff_key( 552 - array_flip($properties), 553 - array_flip($columns)); 554 - } 555 - 556 - $pattern = 'SELECT '.$column.' FROM %T WHERE '.$pattern.' %Q'; 489 + $pattern = 'SELECT * FROM %T WHERE '.$pattern.' %Q'; 557 490 array_unshift($args, $this->getTableName()); 558 - if ($columns) { 559 - array_unshift($args, $columns); 560 - } 561 491 array_push($args, $lock_clause); 562 492 array_unshift($args, $pattern); 563 493 ··· 1141 1071 1142 1072 $this->willSaveObject(); 1143 1073 $data = $this->getPropertyValues(); 1144 - if ($this->getConfigOption(self::CONFIG_PARTIAL_OBJECTS)) { 1145 - $data = array_intersect_key($data, $this->dirtyFields); 1146 - } 1147 1074 $this->willWriteData($data); 1148 1075 1149 1076 $map = array(); ··· 1175 1102 // to catch this for objects which track them if we wanted. 1176 1103 1177 1104 $this->didWriteData(); 1178 - 1179 - if ($this->getConfigOption(self::CONFIG_PARTIAL_OBJECTS)) { 1180 - $this->resetDirtyFields(); 1181 - } 1182 1105 1183 1106 return $this; 1184 1107 } ··· 1286 1209 1287 1210 $this->didWriteData(); 1288 1211 1289 - if ($this->getConfigOption(self::CONFIG_PARTIAL_OBJECTS)) { 1290 - $this->resetDirtyFields(); 1291 - } 1292 - 1293 1212 return $this; 1294 1213 } 1295 1214 ··· 1681 1600 } 1682 1601 1683 1602 /** 1684 - * Resets the dirty fields (fields which need to be written on next save/ 1685 - * update/insert/replace). If this DAO has timestamps, the modified time 1686 - * is always a dirty field. 1687 - * 1688 - * @task util 1689 - */ 1690 - private function resetDirtyFields() { 1691 - $this->dirtyFields = array(); 1692 - if ($this->getConfigOption(self::CONFIG_TIMESTAMPS)) { 1693 - $this->dirtyFields['dateModified'] = true; 1694 - } 1695 - } 1696 - 1697 - /** 1698 1603 * Black magic. Builds implied get*() and set*() for all properties. 1699 1604 * 1700 1605 * @param string Method name. ··· 1719 1624 // optimizations. 1720 1625 1721 1626 static $dispatch_map = array(); 1722 - static $partial = null; 1723 - if ($partial === null) { 1724 - $partial = $this->getConfigOption(self::CONFIG_PARTIAL_OBJECTS); 1725 - } 1726 1627 1727 1628 if ($method[0] === 'g') { 1728 1629 if (isset($dispatch_map[$method])) { ··· 1738 1639 $dispatch_map[$method] = $property; 1739 1640 } 1740 1641 1741 - if ($partial && isset($this->missingFields[$property])) { 1742 - throw new Exception("Cannot get field that wasn't loaded: {$property}"); 1743 - } 1744 - 1745 1642 return $this->readField($property); 1746 1643 } 1747 1644 ··· 1758 1655 throw new Exception("Bad setter call: {$method}"); 1759 1656 } 1760 1657 $dispatch_map[$method] = $property; 1761 - } 1762 - if ($partial) { 1763 - // Accept writes to fields that weren't initially loaded 1764 - unset($this->missingFields[$property]); 1765 - $this->dirtyFields[$property] = true; 1766 1658 } 1767 1659 1768 1660 $this->writeField($property, $args[0]);