mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-29 17:00:59 +01:00
Filter pastes at the query level if we're unable to load their content
Summary: Fixes T8230. I think I broke this in D12354 since I missed the fact that this could filter results, because it's constructed in a sort of weird way. Try to make the logic a little more clear, while retaining the relevant properties: - Pastes with unloadable content should be discarded; - the input order should be retained in the result set. Test Plan: Faked content misses and saw things work instead of fatal. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T8230 Differential Revision: https://secure.phabricator.com/D12909
This commit is contained in:
parent
78dddf39ba
commit
b0862a8176
1 changed files with 23 additions and 6 deletions
|
@ -90,7 +90,7 @@ final class PhabricatorPasteQuery
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->needContent) {
|
if ($this->needContent) {
|
||||||
$this->loadContent($pastes);
|
$pastes = $this->loadContent($pastes);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $pastes;
|
return $pastes;
|
||||||
|
@ -205,31 +205,48 @@ final class PhabricatorPasteQuery
|
||||||
$caches = $cache->getKeys($keys);
|
$caches = $cache->getKeys($keys);
|
||||||
|
|
||||||
$need_raw = array();
|
$need_raw = array();
|
||||||
foreach ($pastes as $key => $paste) {
|
$have_cache = array();
|
||||||
|
foreach ($pastes as $paste) {
|
||||||
$key = $this->getContentCacheKey($paste);
|
$key = $this->getContentCacheKey($paste);
|
||||||
if (isset($caches[$key])) {
|
if (isset($caches[$key])) {
|
||||||
$paste->attachContent(phutil_safe_html($caches[$key]));
|
$paste->attachContent(phutil_safe_html($caches[$key]));
|
||||||
|
$have_cache[$paste->getPHID()] = true;
|
||||||
} else {
|
} else {
|
||||||
$need_raw[$key] = $paste;
|
$need_raw[$key] = $paste;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$need_raw) {
|
if (!$need_raw) {
|
||||||
return;
|
return $pastes;
|
||||||
}
|
}
|
||||||
|
|
||||||
$write_data = array();
|
$write_data = array();
|
||||||
|
|
||||||
$need_raw = $this->loadRawContent($need_raw);
|
$have_raw = $this->loadRawContent($need_raw);
|
||||||
foreach ($need_raw as $key => $paste) {
|
$have_raw = mpull($have_raw, null, 'getPHID');
|
||||||
|
foreach ($pastes as $key => $paste) {
|
||||||
|
$paste_phid = $paste->getPHID();
|
||||||
|
if (isset($have_cache[$paste_phid])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($have_raw[$paste_phid])) {
|
||||||
|
unset($pastes[$key]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$content = $this->buildContent($paste);
|
$content = $this->buildContent($paste);
|
||||||
$paste->attachContent($content);
|
$paste->attachContent($content);
|
||||||
$write_data[$this->getContentCacheKey($paste)] = (string)$content;
|
$write_data[$this->getContentCacheKey($paste)] = (string)$content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($write_data) {
|
||||||
$cache->setKeys($write_data);
|
$cache->setKeys($write_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $pastes;
|
||||||
|
}
|
||||||
|
|
||||||
private function buildContent(PhabricatorPaste $paste) {
|
private function buildContent(PhabricatorPaste $paste) {
|
||||||
$language = $paste->getLanguage();
|
$language = $paste->getLanguage();
|
||||||
$source = $paste->getRawContent();
|
$source = $paste->getRawContent();
|
||||||
|
|
Loading…
Reference in a new issue