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

Fix an issue where "bin/differential migrate-hunk" could decompress data

Summary:
Fixes T12986. I caught this bug in the changes from D18584: when we moved a large hunk to file storage, we would decompress it but keep the "deflated" flag. This could cause confusion when loading it later. I missed this in testing since I wasn't exhaustive enough in checking hunks and didn't run into a compressed one.

Instead of compressing on `save()`, compress during the normal workflow.

We currently never advise users to run this workflow so I didn't bother trying to clean up possible existing migrations.

Test Plan:
- Ran `bin/differential migrate-hunk` on compressed hunks, moving them to and from file storage. Saw them work correctly and remain compressed.
- Created new small (uncompressed) and large (compressed) hunks, verified they work properly and get compressed (if applicable).
- Used `bin/cache purge --caches changeset` to clear changeset caches and make sure the actual table was being hit.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T12986

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

+18 -20
+18 -20
src/applications/differential/storage/DifferentialModernHunk.php
··· 51 51 52 52 $this->dataEncoding = $this->detectEncodingForStorage($text); 53 53 $this->dataType = self::DATATYPE_TEXT; 54 - $this->dataFormat = self::DATAFORMAT_RAW; 55 - $this->data = $text; 54 + 55 + list($format, $data) = $this->formatDataForStorage($text); 56 + 57 + $this->dataFormat = $format; 58 + $this->data = $data; 56 59 57 60 return $this; 58 61 } ··· 68 71 return $this; 69 72 } 70 73 71 - public function save() { 72 - 73 - $type = $this->getDataType(); 74 - $format = $this->getDataFormat(); 75 - 76 - // Before saving the data, attempt to compress it. 77 - if ($type == self::DATATYPE_TEXT) { 78 - if ($format == self::DATAFORMAT_RAW) { 79 - $data = $this->getData(); 80 - $deflated = PhabricatorCaches::maybeDeflateData($data); 81 - if ($deflated !== null) { 82 - $this->data = $deflated; 83 - $this->dataFormat = self::DATAFORMAT_DEFLATED; 84 - } 85 - } 74 + private function formatDataForStorage($data) { 75 + $deflated = PhabricatorCaches::maybeDeflateData($data); 76 + if ($deflated !== null) { 77 + return array(self::DATAFORMAT_DEFLATED, $deflated); 86 78 } 87 79 88 - return parent::save(); 80 + return array(self::DATAFORMAT_RAW, $data); 89 81 } 90 82 91 83 public function saveAsText() { ··· 99 91 $raw_data = $this->getRawData(); 100 92 101 93 $this->setDataType(self::DATATYPE_TEXT); 102 - $this->setData($raw_data); 94 + 95 + list($format, $data) = $this->formatDataForStorage($raw_data); 96 + $this->setDataFormat($format); 97 + $this->setData($data); 103 98 104 99 $result = $this->save(); 105 100 ··· 118 113 119 114 $raw_data = $this->getRawData(); 120 115 116 + list($format, $data) = $this->formatDataForStorage($raw_data); 117 + $this->setDataFormat($format); 118 + 121 119 $file = PhabricatorFile::newFromFileData( 122 - $raw_data, 120 + $data, 123 121 array( 124 122 'name' => 'differential-hunk', 125 123 'mime-type' => 'application/octet-stream',