Skip to content

Commit b91c863

Browse files
author
epriestley
committed
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
1 parent aec0e2f commit b91c863

File tree

1 file changed

+29
-15
lines changed

1 file changed

+29
-15
lines changed

src/applications/paste/query/PhabricatorPasteQuery.php

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,20 @@ protected function loadPage() {
5555

5656
$pastes = $table->loadAllFromArray($data);
5757

58-
if ($pastes && $this->needRawContent) {
59-
$this->loadRawContent($pastes);
58+
return $pastes;
59+
}
60+
61+
protected function willFilterPage(array $pastes) {
62+
if (!$pastes) {
63+
return $pastes;
6064
}
6165

62-
if ($pastes && $this->needContent) {
63-
$this->loadContent($pastes);
66+
if ($this->needRawContent) {
67+
$pastes = $this->loadRawContent($pastes);
68+
}
69+
70+
if ($this->needContent) {
71+
$pastes = $this->loadContent($pastes);
6472
}
6573

6674
return $pastes;
@@ -113,14 +121,16 @@ private function loadRawContent(array $pastes) {
113121
$file_phids);
114122
$files = mpull($files, null, 'getPHID');
115123

116-
foreach ($pastes as $paste) {
124+
foreach ($pastes as $key => $paste) {
117125
$file = idx($files, $paste->getFilePHID());
118-
if ($file) {
119-
$paste->attachRawContent($file->loadFileData());
120-
} else {
121-
$paste->attachRawContent('');
126+
if (!$file) {
127+
unset($pastes[$key]);
128+
continue;
122129
}
130+
$paste->attachRawContent($file->loadFileData());
123131
}
132+
133+
return $pastes;
124134
}
125135

126136
private function loadContent(array $pastes) {
@@ -134,34 +144,38 @@ private function loadContent(array $pastes) {
134144
$keys[] = $this->getContentCacheKey($paste);
135145
}
136146

137-
138147
$caches = $cache->getKeys($keys);
148+
$results = array();
139149

140150
$need_raw = array();
141-
foreach ($pastes as $paste) {
151+
foreach ($pastes as $key => $paste) {
142152
$key = $this->getContentCacheKey($paste);
143153
if (isset($caches[$key])) {
144154
$paste->attachContent(phutil_safe_html($caches[$key]));
155+
$results[$key] = $paste;
145156
} else {
146-
$need_raw[] = $paste;
157+
$need_raw[$key] = $paste;
147158
}
148159
}
149160

150161
if (!$need_raw) {
151-
return;
162+
return $results;
152163
}
153164

154165
$write_data = array();
155166

156-
$this->loadRawContent($need_raw);
157-
foreach ($need_raw as $paste) {
167+
$need_raw = $this->loadRawContent($need_raw);
168+
foreach ($need_raw as $key => $paste) {
158169
$content = $this->buildContent($paste);
159170
$paste->attachContent($content);
160171

161172
$write_data[$this->getContentCacheKey($paste)] = (string)$content;
173+
$results[$key] = $paste;
162174
}
163175

164176
$cache->setKeys($write_data);
177+
178+
return $results;
165179
}
166180

167181

0 commit comments

Comments
 (0)