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

When rendering "{image ...}" images, check the cache and just render a direct "<img />" tag if possible

Summary: Depends on D19193. Ref T13101. Fixes T4190. Before we render a fancy AJAX placeholder, check if we already have a valid cache for the image. If we do, render a direct `<img />` tag. This is a little cleaner and, e.g., avoids flicker in Safari, at least.

Test Plan: Rendered `{image ...}` rules in remarkup with new and existing URIs.

Maniphest Tasks: T13101, T4190

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

+59 -7
+59 -7
src/applications/files/markup/PhabricatorImageRemarkupRule.php
··· 94 94 return; 95 95 } 96 96 97 + // Look for images we've already successfully fetched that aren't about 98 + // to get eaten by the GC. For any we find, we can just emit a normal 99 + // "<img />" tag pointing directly to the file. 100 + 101 + // For files which we don't hit in the cache, we emit a placeholder 102 + // instead and use AJAX to actually perform the fetch. 103 + 104 + $digests = array(); 105 + foreach ($images as $image) { 106 + $uri = $image['args']['uri']; 107 + $digests[] = PhabricatorHash::digestForIndex($uri); 108 + } 109 + 110 + $caches = id(new PhabricatorFileExternalRequest())->loadAllWhere( 111 + 'uriIndex IN (%Ls) AND isSuccessful = 1 AND ttl > %d', 112 + $digests, 113 + PhabricatorTime::getNow() + phutil_units('1 hour in seconds')); 114 + 115 + $file_phids = array(); 116 + foreach ($caches as $cache) { 117 + $file_phids[$cache->getFilePHID()] = $cache->getURI(); 118 + } 119 + 120 + $file_map = array(); 121 + if ($file_phids) { 122 + $files = id(new PhabricatorFileQuery()) 123 + ->setViewer(PhabricatorUser::getOmnipotentUser()) 124 + ->withPHIDs(array_keys($file_phids)) 125 + ->execute(); 126 + foreach ($files as $file) { 127 + $phid = $file->getPHID(); 128 + 129 + $file_remote_uri = $file_phids[$phid]; 130 + $file_view_uri = $file->getViewURI(); 131 + 132 + $file_map[$file_remote_uri] = $file_view_uri; 133 + } 134 + } 135 + 97 136 foreach ($images as $image) { 98 137 $args = $image['args']; 138 + $uri = $args['uri']; 99 139 100 - $src_uri = id(new PhutilURI('/file/imageproxy/')) 101 - ->setQueryParam('uri', $args['uri']); 140 + $direct_uri = idx($file_map, $uri); 141 + if ($direct_uri) { 142 + $img = phutil_tag( 143 + 'img', 144 + array( 145 + 'src' => $direct_uri, 146 + 'alt' => $args['alt'], 147 + 'width' => $args['width'], 148 + 'height' => $args['height'], 149 + )); 150 + } else { 151 + $src_uri = id(new PhutilURI('/file/imageproxy/')) 152 + ->setQueryParam('uri', $uri); 102 153 103 - $img = id(new PHUIRemarkupImageView()) 104 - ->setURI($src_uri) 105 - ->setAlt($args['alt']) 106 - ->setWidth($args['width']) 107 - ->setHeight($args['height']); 154 + $img = id(new PHUIRemarkupImageView()) 155 + ->setURI($src_uri) 156 + ->setAlt($args['alt']) 157 + ->setWidth($args['width']) 158 + ->setHeight($args['height']); 159 + } 108 160 109 161 $engine->overwriteStoredText($image['token'], $img); 110 162 }