mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-18 21:02:41 +01:00
Fix Feed Times on 32 Bit Servers
Summary: The feed time is stored as the upper 32 bits of PhabricatorFeedStoryData::chronologicalKey. These bits were previously accessed by right shifting, which does not work properly on 32 bit machines (the result is PHP_INT_MAX). We now attempt to use the bc extension (if available) and fall back on mysql math otherwise. (See T500, D912). Test Plan: The calculation is unchanged for 64 bit machines. I checked both paths on a 32 bit machine with bc extension available by setting the appropriate if-condition to false and true. Reviewers: epriestley Reviewed By: epriestley CC: ddfisher, aran, epriestley Differential Revision: https://secure.phabricator.com/D1726
This commit is contained in:
parent
9b318e4044
commit
e846a1747e
2 changed files with 23 additions and 2 deletions
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2011 Facebook, Inc.
|
* Copyright 2012 Facebook, Inc.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -40,7 +40,27 @@ class PhabricatorFeedStoryData extends PhabricatorFeedDAO {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getEpoch() {
|
public function getEpoch() {
|
||||||
return $this->chronologicalKey >> 32;
|
if (PHP_INT_SIZE < 8) {
|
||||||
|
// We're on a 32-bit machine.
|
||||||
|
if (function_exists('bcadd')) {
|
||||||
|
// Try to use the 'bc' extension.
|
||||||
|
return bcdiv($this->chronologicalKey, bcpow(2,32));
|
||||||
|
} else {
|
||||||
|
// Do the math in MySQL. TODO: If we formalize a bc dependency, get
|
||||||
|
// rid of this.
|
||||||
|
// See: PhabricatorFeedStoryPublisher::generateChronologicalKey()
|
||||||
|
$conn_r = id($this->establishConnection('r'));
|
||||||
|
$result = queryfx_one(
|
||||||
|
$conn_r,
|
||||||
|
// Insert the chronologicalKey as a string since longs don't seem to
|
||||||
|
// be supported by qsprintf and ints get maxed on 32 bit machines.
|
||||||
|
'SELECT (%s >> 32) as N',
|
||||||
|
$this->chronologicalKey);
|
||||||
|
return $result['N'];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return $this->chronologicalKey >> 32;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getValue($key, $default = null) {
|
public function getValue($key, $default = null) {
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
phutil_require_module('phabricator', 'applications/feed/storage/base');
|
phutil_require_module('phabricator', 'applications/feed/storage/base');
|
||||||
phutil_require_module('phabricator', 'applications/phid/constants');
|
phutil_require_module('phabricator', 'applications/phid/constants');
|
||||||
phutil_require_module('phabricator', 'applications/phid/storage/phid');
|
phutil_require_module('phabricator', 'applications/phid/storage/phid');
|
||||||
|
phutil_require_module('phabricator', 'storage/queryfx');
|
||||||
|
|
||||||
phutil_require_module('phutil', 'utils');
|
phutil_require_module('phutil', 'utils');
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue