@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Allow Multimeter values to be locked by clicking links

Summary: Ref T6930. Mostly just playing with the UI a bit, I imagine we'll end up somewhere with a set of more standard query tools in the long run. But this feels pretty good/natural so far.

Test Plan: {F389685}

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T6930

Differential Revision: https://secure.phabricator.com/D12628

+107 -17
+107 -17
src/applications/multimeter/controller/MultimeterSampleController.php
··· 8 8 9 9 public function handleRequest(AphrontRequest $request) { 10 10 $viewer = $this->getViewer(); 11 - 12 - $group_map = array( 13 - 'type' => 'eventType', 14 - 'host' => 'eventHostID', 15 - 'context' => 'eventContextID', 16 - 'viewer' => 'eventViewerID', 17 - 'request' => 'requestKey', 18 - 'label' => 'eventLabelID', 19 - ); 11 + $group_map = $this->getColumnMap(); 20 12 21 13 $group = explode('.', $request->getStr('group')); 22 14 $group = array_intersect($group, array_keys($group_map)); ··· 31 23 32 24 $table = new MultimeterEvent(); 33 25 $conn = $table->establishConnection('r'); 26 + 27 + $where = array(); 28 + $where[] = qsprintf( 29 + $conn, 30 + 'epoch >= %d AND epoch <= %d', 31 + $ago, 32 + $now); 33 + 34 + $with = array(); 35 + foreach ($group_map as $key => $column) { 36 + $with[$key] = $request->getStrList($key); 37 + if ($with[$key]) { 38 + $where[] = qsprintf( 39 + $conn, 40 + '%T IN (%Ls)', 41 + $column, 42 + $with[$key]); 43 + } 44 + } 45 + 46 + $where = '('.implode(') AND (', $where).')'; 47 + 34 48 $data = queryfx_all( 35 49 $conn, 36 50 'SELECT *, count(*) N, SUM(sampleRate * resourceCost) as totalCost 37 51 FROM %T 38 - WHERE epoch >= %d AND epoch <= %d 52 + WHERE %Q 39 53 GROUP BY %Q 40 54 ORDER BY totalCost DESC, MAX(id) DESC 41 55 LIMIT 100', 42 56 $table->getTableName(), 43 - $ago, 44 - $now, 57 + $where, 45 58 implode(', ', array_select_keys($group_map, $group))); 46 59 47 60 $this->loadDimensions($data); ··· 51 64 52 65 if (isset($group['request'])) { 53 66 $request_col = $row['requestKey']; 67 + if (!$with['request']) { 68 + $request_col = $this->renderSelectionLink( 69 + 'request', 70 + $row['requestKey'], 71 + $request_col); 72 + } 54 73 } else { 55 74 $request_col = $this->renderGroupingLink($group, 'request'); 56 75 } ··· 58 77 if (isset($group['viewer'])) { 59 78 $viewer_col = $this->getViewerDimension($row['eventViewerID']) 60 79 ->getName(); 80 + if (!$with['viewer']) { 81 + $viewer_col = $this->renderSelectionLink( 82 + 'viewer', 83 + $row['eventViewerID'], 84 + $viewer_col); 85 + } 61 86 } else { 62 87 $viewer_col = $this->renderGroupingLink($group, 'viewer'); 63 88 } ··· 65 90 if (isset($group['context'])) { 66 91 $context_col = $this->getContextDimension($row['eventContextID']) 67 92 ->getName(); 93 + if (!$with['context']) { 94 + $context_col = $this->renderSelectionLink( 95 + 'context', 96 + $row['eventContextID'], 97 + $context_col); 98 + } 68 99 } else { 69 100 $context_col = $this->renderGroupingLink($group, 'context'); 70 101 } ··· 72 103 if (isset($group['host'])) { 73 104 $host_col = $this->getHostDimension($row['eventHostID']) 74 105 ->getName(); 106 + if (!$with['host']) { 107 + $host_col = $this->renderSelectionLink( 108 + 'host', 109 + $row['eventHostID'], 110 + $host_col); 111 + } 75 112 } else { 76 113 $host_col = $this->renderGroupingLink($group, 'host'); 77 114 } ··· 79 116 if (isset($group['label'])) { 80 117 $label_col = $this->getLabelDimension($row['eventLabelID']) 81 118 ->getName(); 119 + if (!$with['label']) { 120 + $label_col = $this->renderSelectionLink( 121 + 'label', 122 + $row['eventLabelID'], 123 + $label_col); 124 + } 82 125 } else { 83 126 $label_col = $this->renderGroupingLink($group, 'label'); 84 127 } 85 128 129 + if ($with['type']) { 130 + $type_col = MultimeterEvent::getEventTypeName($row['eventType']); 131 + } else { 132 + $type_col = $this->renderSelectionLink( 133 + 'type', 134 + $row['eventType'], 135 + MultimeterEvent::getEventTypeName($row['eventType'])); 136 + } 137 + 86 138 $rows[] = array( 87 139 ($row['N'] == 1) 88 140 ? $row['id'] ··· 91 143 $viewer_col, 92 144 $context_col, 93 145 $host_col, 94 - MultimeterEvent::getEventTypeName($row['eventType']), 146 + $type_col, 95 147 $label_col, 96 148 MultimeterEvent::formatResourceCost( 97 149 $viewer, ··· 139 191 ->appendChild($table); 140 192 141 193 $crumbs = $this->buildApplicationCrumbs(); 142 - $crumbs->addTextCrumb(pht('Samples'), $this->getGroupURI(array())); 194 + $crumbs->addTextCrumb( 195 + pht('Samples'), 196 + $this->getGroupURI(array(), true)); 143 197 144 198 $crumb_map = array( 145 199 'host' => pht('By Host'), ··· 157 211 $parts[$item] = $item; 158 212 $crumbs->addTextCrumb( 159 213 idx($crumb_map, $item, $item), 160 - $this->getGroupURI($parts)); 214 + $this->getGroupURI($parts, true)); 161 215 } 162 216 163 217 return $this->buildApplicationPage( ··· 183 237 pht('(All)')); 184 238 } 185 239 186 - private function getGroupURI(array $group) { 240 + private function getGroupURI(array $group, $wipe = false) { 187 241 unset($group['type']); 188 242 $uri = clone $this->getRequest()->getRequestURI(); 189 - $uri->setQueryParam('group', implode('.', $group)); 243 + 244 + $group = implode('.', $group); 245 + if (!strlen($group)) { 246 + $group = null; 247 + } 248 + $uri->setQueryParam('group', $group); 249 + 250 + if ($wipe) { 251 + foreach ($this->getColumnMap() as $key => $column) { 252 + $uri->setQueryParam($key, null); 253 + } 254 + } 255 + 190 256 return $uri; 191 257 } 192 258 259 + private function renderSelectionLink($key, $value, $link_text) { 260 + $value = (array)$value; 261 + 262 + $uri = clone $this->getRequest()->getRequestURI(); 263 + $uri->setQueryParam($key, implode(',', $value)); 264 + 265 + return phutil_tag( 266 + 'a', 267 + array( 268 + 'href' => $uri, 269 + ), 270 + $link_text); 271 + } 272 + 273 + private function getColumnMap() { 274 + return array( 275 + 'type' => 'eventType', 276 + 'host' => 'eventHostID', 277 + 'context' => 'eventContextID', 278 + 'viewer' => 'eventViewerID', 279 + 'request' => 'requestKey', 280 + 'label' => 'eventLabelID', 281 + ); 282 + } 193 283 194 284 }