|
10 | 10 | use Badoo\LiveProfilerUI\DataProviders\Interfaces\SourceInterface; |
11 | 11 | use Badoo\LiveProfilerUI\DataProviders\Interfaces\JobInterface; |
12 | 12 | use Badoo\LiveProfilerUI\DataProviders\Interfaces\MethodInterface; |
| 13 | +use Badoo\LiveProfilerUI\DataProviders\Interfaces\MethodDataInterface; |
13 | 14 | use Badoo\LiveProfilerUI\DataProviders\Interfaces\SnapshotInterface; |
| 15 | +use Badoo\LiveProfilerUI\FieldList; |
14 | 16 |
|
15 | 17 | class AjaxPages |
16 | 18 | { |
17 | 19 | /** @var SnapshotInterface */ |
18 | 20 | protected $Snapshot; |
19 | 21 | /** @var MethodInterface */ |
20 | 22 | protected $Method; |
| 23 | + /** @var MethodDataInterface */ |
| 24 | + protected $MethodData; |
21 | 25 | /** @var JobInterface */ |
22 | 26 | protected $Job; |
23 | 27 | /** @var Aggregator */ |
24 | 28 | protected $Aggregator; |
25 | 29 | /** @var SourceInterface */ |
26 | 30 | protected $Source; |
| 31 | + /** @var FieldList */ |
| 32 | + protected $FieldList; |
27 | 33 | /** @var bool */ |
28 | 34 | protected $use_jobs; |
29 | 35 |
|
30 | 36 | public function __construct( |
31 | 37 | SnapshotInterface $Snapshot, |
32 | 38 | MethodInterface $Method, |
| 39 | + MethodDataInterface $MethodData, |
33 | 40 | JobInterface $Job, |
34 | 41 | Aggregator $Aggregator, |
35 | 42 | SourceInterface $Source, |
| 43 | + FieldList $FieldList, |
36 | 44 | bool $use_jobs = false |
37 | 45 | ) { |
38 | 46 | $this->Snapshot = $Snapshot; |
39 | 47 | $this->Method = $Method; |
| 48 | + $this->MethodData = $MethodData; |
40 | 49 | $this->Job = $Job; |
41 | 50 | $this->Aggregator = $Aggregator; |
42 | 51 | $this->Source = $Source; |
| 52 | + $this->FieldList = $FieldList; |
43 | 53 | $this->use_jobs = $use_jobs; |
44 | 54 | } |
45 | 55 |
|
@@ -160,6 +170,63 @@ public function searchMethods(string $term) : array |
160 | 170 | } |
161 | 171 | } |
162 | 172 |
|
| 173 | + public function getMethodUsedApps(string $method_name) : array |
| 174 | + { |
| 175 | + $method_name = ltrim($method_name, '\\'); |
| 176 | + try { |
| 177 | + $methods = $this->Method->findByName($method_name, true); |
| 178 | + if (!$methods) { |
| 179 | + return []; |
| 180 | + } |
| 181 | + |
| 182 | + $method = current($methods); |
| 183 | + |
| 184 | + $last_two_days = \Badoo\LiveProfilerUI\DateGenerator::getDatesArray(date('Y-m-d'), 2, 2); |
| 185 | + $start_snapshot_id = in_array(current($methods)['date'], $last_two_days, true) |
| 186 | + ? $this->Snapshot->getMinSnapshotIdByDates($last_two_days) |
| 187 | + : 0; |
| 188 | + |
| 189 | + $method_data = $this->MethodData->getDataByMethodIdsAndSnapshotIds( |
| 190 | + [], |
| 191 | + [$method['id']], |
| 192 | + 100, |
| 193 | + $start_snapshot_id |
| 194 | + ); |
| 195 | + |
| 196 | + $snapshot_ids = []; |
| 197 | + foreach ($method_data as $Row) { |
| 198 | + $snapshot_id = $Row->getSnapshotId(); |
| 199 | + $snapshot_ids[$snapshot_id] = $snapshot_id; |
| 200 | + } |
| 201 | + $snapshots = $this->Snapshot->getListByIds($snapshot_ids); |
| 202 | + |
| 203 | + $fields = $this->FieldList->getFields(); |
| 204 | + |
| 205 | + $results = []; |
| 206 | + foreach ($method_data as $Row) { |
| 207 | + $result = []; |
| 208 | + $result['app'] = $snapshots[$Row->getSnapshotId()]['app']; |
| 209 | + $result['label'] = $snapshots[$Row->getSnapshotId()]['label']; |
| 210 | + |
| 211 | + $uniq_key = $result['app'] . '_' . $result['label']; |
| 212 | + if (!empty($results[$uniq_key])) { |
| 213 | + continue; |
| 214 | + } |
| 215 | + |
| 216 | + $values = $Row->getFormattedValues(); |
| 217 | + foreach ($fields as $field) { |
| 218 | + $result['fields'][$field] = $values[$field]; |
| 219 | + } |
| 220 | + $result['fields']['calls_count'] = $snapshots[$Row->getSnapshotId()]['calls_count']; |
| 221 | + |
| 222 | + $results[$uniq_key] = $result; |
| 223 | + } |
| 224 | + return array_values($results); |
| 225 | + } catch (\Throwable $Ex) { |
| 226 | + return []; |
| 227 | + } |
| 228 | + } |
| 229 | + |
163 | 230 | public function allMethods() : array |
164 | 231 | { |
165 | 232 | try { |
|
0 commit comments