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

Don't compute MIME type of noninitial chunks from `diffusion.filecontentquery`

Summary:
Ref T12857. This is generally fairly fuzzy for now, but here's something concrete: when we build a large file with `diffusion.filecontentquery`, we compute the MIME type of all chunks, not just the initial chunk.

Instead, pass a dummy MIME type to non-initial chunks so we don't try to compute them. This mirrors logic elsewhere, in `file.uploadchunk`. This should perhaps be centralized at some point, but it's a bit tricky since the file doesn't know that it's a chunk until later.

Also, clean up the `TempFile` immediately -- this shouldn't actually affect anything, but we don't need it to live any longer than this.

Test Plan:
- Made `hashFileContent()` return `null` to skip the chunk cache.
- Added `phlog()` to the MIME type computation.
- Loaded a 12MB file in Diffusion.
- Before patch: Saw 3x MIME type computations, one for each 4MB chunk.
- After patch: Saw 1x MIME type computation, for initial chunk only.

Reviewers: chad, amckinley

Reviewed By: chad

Maniphest Tasks: T12857

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

+13 -6
+1
src/applications/files/storage/PhabricatorFile.php
··· 393 393 $tmp = new TempFile(); 394 394 Filesystem::writeFile($tmp, $data); 395 395 $file->setMimeType(Filesystem::getMimeType($tmp)); 396 + unset($tmp); 396 397 } 397 398 398 399 try {
+12 -6
src/applications/files/uploadsource/PhabricatorFileUploadSource.php
··· 186 186 $actual_length = strlen($data); 187 187 $rope->removeBytesFromHead($actual_length); 188 188 189 - $chunk_data = PhabricatorFile::newFromFileData( 190 - $data, 191 - array( 192 - 'name' => $file->getMonogram().'.chunk-'.$offset, 193 - 'viewPolicy' => PhabricatorPolicies::POLICY_NOONE, 194 - )); 189 + $params = array( 190 + 'name' => $file->getMonogram().'.chunk-'.$offset, 191 + 'viewPolicy' => PhabricatorPolicies::POLICY_NOONE, 192 + ); 193 + 194 + // If this isn't the initial chunk, provide a dummy MIME type so we do not 195 + // try to detect it. See T12857. 196 + if ($offset > 0) { 197 + $params['mime-type'] = 'application/octet-stream'; 198 + } 199 + 200 + $chunk_data = PhabricatorFile::newFromFileData($data, $params); 195 201 196 202 $chunk = PhabricatorFileChunk::initializeNewChunk( 197 203 $file->getStorageHandle(),