From e846a1747ef3b9eeab2afe89f52be04f4abe6161 Mon Sep 17 00:00:00 2001 From: David Fisher Date: Tue, 28 Feb 2012 21:03:49 -0800 Subject: [PATCH] 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 --- .../story/PhabricatorFeedStoryData.php | 24 +++++++++++++++++-- .../feed/storage/story/__init__.php | 1 + 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/applications/feed/storage/story/PhabricatorFeedStoryData.php b/src/applications/feed/storage/story/PhabricatorFeedStoryData.php index 0050a9ffd7..36519fe56a 100644 --- a/src/applications/feed/storage/story/PhabricatorFeedStoryData.php +++ b/src/applications/feed/storage/story/PhabricatorFeedStoryData.php @@ -1,7 +1,7 @@ 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) { diff --git a/src/applications/feed/storage/story/__init__.php b/src/applications/feed/storage/story/__init__.php index 831e139d30..8e4defec91 100644 --- a/src/applications/feed/storage/story/__init__.php +++ b/src/applications/feed/storage/story/__init__.php @@ -9,6 +9,7 @@ phutil_require_module('phabricator', 'applications/feed/storage/base'); phutil_require_module('phabricator', 'applications/phid/constants'); phutil_require_module('phabricator', 'applications/phid/storage/phid'); +phutil_require_module('phabricator', 'storage/queryfx'); phutil_require_module('phutil', 'utils');