Page MenuHomePhabricator

D19194.diff
No OneTemporary

D19194.diff

diff --git a/src/applications/files/markup/PhabricatorImageRemarkupRule.php b/src/applications/files/markup/PhabricatorImageRemarkupRule.php
--- a/src/applications/files/markup/PhabricatorImageRemarkupRule.php
+++ b/src/applications/files/markup/PhabricatorImageRemarkupRule.php
@@ -94,17 +94,69 @@
return;
}
+ // Look for images we've already successfully fetched that aren't about
+ // to get eaten by the GC. For any we find, we can just emit a normal
+ // "<img />" tag pointing directly to the file.
+
+ // For files which we don't hit in the cache, we emit a placeholder
+ // instead and use AJAX to actually perform the fetch.
+
+ $digests = array();
foreach ($images as $image) {
- $args = $image['args'];
+ $uri = $image['args']['uri'];
+ $digests[] = PhabricatorHash::digestForIndex($uri);
+ }
+
+ $caches = id(new PhabricatorFileExternalRequest())->loadAllWhere(
+ 'uriIndex IN (%Ls) AND isSuccessful = 1 AND ttl > %d',
+ $digests,
+ PhabricatorTime::getNow() + phutil_units('1 hour in seconds'));
+
+ $file_phids = array();
+ foreach ($caches as $cache) {
+ $file_phids[$cache->getFilePHID()] = $cache->getURI();
+ }
- $src_uri = id(new PhutilURI('/file/imageproxy/'))
- ->setQueryParam('uri', $args['uri']);
+ $file_map = array();
+ if ($file_phids) {
+ $files = id(new PhabricatorFileQuery())
+ ->setViewer(PhabricatorUser::getOmnipotentUser())
+ ->withPHIDs(array_keys($file_phids))
+ ->execute();
+ foreach ($files as $file) {
+ $phid = $file->getPHID();
- $img = id(new PHUIRemarkupImageView())
- ->setURI($src_uri)
- ->setAlt($args['alt'])
- ->setWidth($args['width'])
- ->setHeight($args['height']);
+ $file_remote_uri = $file_phids[$phid];
+ $file_view_uri = $file->getViewURI();
+
+ $file_map[$file_remote_uri] = $file_view_uri;
+ }
+ }
+
+ foreach ($images as $image) {
+ $args = $image['args'];
+ $uri = $args['uri'];
+
+ $direct_uri = idx($file_map, $uri);
+ if ($direct_uri) {
+ $img = phutil_tag(
+ 'img',
+ array(
+ 'src' => $direct_uri,
+ 'alt' => $args['alt'],
+ 'width' => $args['width'],
+ 'height' => $args['height'],
+ ));
+ } else {
+ $src_uri = id(new PhutilURI('/file/imageproxy/'))
+ ->setQueryParam('uri', $uri);
+
+ $img = id(new PHUIRemarkupImageView())
+ ->setURI($src_uri)
+ ->setAlt($args['alt'])
+ ->setWidth($args['width'])
+ ->setHeight($args['height']);
+ }
$engine->overwriteStoredText($image['token'], $img);
}

File Metadata

Mime Type
text/plain
Expires
Sun, Mar 16, 4:39 AM (3 d, 2 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7705786
Default Alt Text
D19194.diff (2 KB)

Event Timeline