mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-19 05:12:41 +01:00
Fix generateChronologicalKey() for 32-bit machines
Summary: This method relies on 64-bit math being available, which isn't a safe assumption. Use the builtin bc functions instead for arbitrarily large integers. Test Plan: @skrul, can you apply this locally and let me know if it works? Reviewers: skrul, hunterbridges, jungejason, nh, tuomaspelkonen, aran Reviewed By: skrul CC: aran, skrul, epriestley Differential Revision: 912
This commit is contained in:
parent
4bec2579d5
commit
9215d330ad
2 changed files with 22 additions and 2 deletions
|
@ -108,6 +108,26 @@ final class PhabricatorFeedStoryPublisher {
|
|||
// Generate a random number for the lower 32 bits of the key.
|
||||
$rand = head(unpack('L', Filesystem::readRandomBytes(4)));
|
||||
|
||||
return ($time << 32) + ($rand);
|
||||
// On 32-bit machines, we have to get creative.
|
||||
if (PHP_INT_SIZE < 8) {
|
||||
// We're on a 32-bit machine.
|
||||
if (function_exists('bcadd')) {
|
||||
// Try to use the 'bc' extension.
|
||||
return bcadd(bcmul($time, bcpow(2, 32)), $rand);
|
||||
} else {
|
||||
// Do the math in MySQL. TODO: If we formalize a bc dependency, get
|
||||
// rid of this.
|
||||
$conn_r = id(new PhabricatorFeedStoryData())->establishConnection('r');
|
||||
$result = queryfx_one(
|
||||
$conn_r,
|
||||
'SELECT (%d << 32) + %d as N',
|
||||
$time,
|
||||
$rand);
|
||||
return $result['N'];
|
||||
}
|
||||
} else {
|
||||
// This is a 64 bit machine, so we can just do the math.
|
||||
return ($time << 32) + $rand;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ class PhabricatorObjectHandleData {
|
|||
private $phids;
|
||||
|
||||
public function __construct(array $phids) {
|
||||
$this->phids = $phids;
|
||||
$this->phids = array_unique($phids);
|
||||
}
|
||||
|
||||
public function loadObjects() {
|
||||
|
|
Loading…
Reference in a new issue