From b91c863780075618e371512967c863c3e2b87918 Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 29 May 2013 06:28:47 -0700 Subject: [PATCH] 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 --- .../paste/query/PhabricatorPasteQuery.php | 44 ++++++++++++------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/src/applications/paste/query/PhabricatorPasteQuery.php b/src/applications/paste/query/PhabricatorPasteQuery.php index d22ab8154d..65794eae94 100644 --- a/src/applications/paste/query/PhabricatorPasteQuery.php +++ b/src/applications/paste/query/PhabricatorPasteQuery.php @@ -55,12 +55,20 @@ final class PhabricatorPasteQuery $pastes = $table->loadAllFromArray($data); - if ($pastes && $this->needRawContent) { - $this->loadRawContent($pastes); + return $pastes; + } + + protected function willFilterPage(array $pastes) { + if (!$pastes) { + return $pastes; } - if ($pastes && $this->needContent) { - $this->loadContent($pastes); + if ($this->needRawContent) { + $pastes = $this->loadRawContent($pastes); + } + + if ($this->needContent) { + $pastes = $this->loadContent($pastes); } return $pastes; @@ -113,14 +121,16 @@ final class PhabricatorPasteQuery $file_phids); $files = mpull($files, null, 'getPHID'); - foreach ($pastes as $paste) { + foreach ($pastes as $key => $paste) { $file = idx($files, $paste->getFilePHID()); - if ($file) { - $paste->attachRawContent($file->loadFileData()); - } else { - $paste->attachRawContent(''); + if (!$file) { + unset($pastes[$key]); + continue; } + $paste->attachRawContent($file->loadFileData()); } + + return $pastes; } private function loadContent(array $pastes) { @@ -134,34 +144,38 @@ final class PhabricatorPasteQuery $keys[] = $this->getContentCacheKey($paste); } - $caches = $cache->getKeys($keys); + $results = array(); $need_raw = array(); - foreach ($pastes as $paste) { + foreach ($pastes as $key => $paste) { $key = $this->getContentCacheKey($paste); if (isset($caches[$key])) { $paste->attachContent(phutil_safe_html($caches[$key])); + $results[$key] = $paste; } else { - $need_raw[] = $paste; + $need_raw[$key] = $paste; } } if (!$need_raw) { - return; + return $results; } $write_data = array(); - $this->loadRawContent($need_raw); - foreach ($need_raw as $paste) { + $need_raw = $this->loadRawContent($need_raw); + foreach ($need_raw as $key => $paste) { $content = $this->buildContent($paste); $paste->attachContent($content); $write_data[$this->getContentCacheKey($paste)] = (string)$content; + $results[$key] = $paste; } $cache->setKeys($write_data); + + return $results; }