1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-26 08:42:41 +01:00

When a paste's file is deleted, drop it from query results

Summary:
We allow files to be deleted from the web UI, including paste files. When a paste's file is deleted, we currently continue to show it in the paste list and then 400 when it's clicked on.

Instead, remove it from the list. (Note that it may stick around if it's cached.)

Test Plan: Purged general cache, deleted a paste's file, viewed paste list, saw no pastes.

Reviewers: dctrwatson, btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T3265

Differential Revision: https://secure.phabricator.com/D6067
This commit is contained in:
epriestley 2013-05-29 06:28:47 -07:00
parent aec0e2f8f9
commit b91c863780

View file

@ -55,12 +55,20 @@ final class PhabricatorPasteQuery
$pastes = $table->loadAllFromArray($data); $pastes = $table->loadAllFromArray($data);
if ($pastes && $this->needRawContent) { return $pastes;
$this->loadRawContent($pastes); }
protected function willFilterPage(array $pastes) {
if (!$pastes) {
return $pastes;
} }
if ($pastes && $this->needContent) { if ($this->needRawContent) {
$this->loadContent($pastes); $pastes = $this->loadRawContent($pastes);
}
if ($this->needContent) {
$pastes = $this->loadContent($pastes);
} }
return $pastes; return $pastes;
@ -113,14 +121,16 @@ final class PhabricatorPasteQuery
$file_phids); $file_phids);
$files = mpull($files, null, 'getPHID'); $files = mpull($files, null, 'getPHID');
foreach ($pastes as $paste) { foreach ($pastes as $key => $paste) {
$file = idx($files, $paste->getFilePHID()); $file = idx($files, $paste->getFilePHID());
if ($file) { if (!$file) {
$paste->attachRawContent($file->loadFileData()); unset($pastes[$key]);
} else { continue;
$paste->attachRawContent('');
} }
$paste->attachRawContent($file->loadFileData());
} }
return $pastes;
} }
private function loadContent(array $pastes) { private function loadContent(array $pastes) {
@ -134,34 +144,38 @@ final class PhabricatorPasteQuery
$keys[] = $this->getContentCacheKey($paste); $keys[] = $this->getContentCacheKey($paste);
} }
$caches = $cache->getKeys($keys); $caches = $cache->getKeys($keys);
$results = array();
$need_raw = array(); $need_raw = array();
foreach ($pastes as $paste) { foreach ($pastes as $key => $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]));
$results[$key] = $paste;
} else { } else {
$need_raw[] = $paste; $need_raw[$key] = $paste;
} }
} }
if (!$need_raw) { if (!$need_raw) {
return; return $results;
} }
$write_data = array(); $write_data = array();
$this->loadRawContent($need_raw); $need_raw = $this->loadRawContent($need_raw);
foreach ($need_raw as $paste) { foreach ($need_raw as $key => $paste) {
$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;
$results[$key] = $paste;
} }
$cache->setKeys($write_data); $cache->setKeys($write_data);
return $results;
} }