Skip to content

Commit 2afcdb8

Browse files
committed
added method-used-apps.json
1 parent f94778f commit 2afcdb8

5 files changed

Lines changed: 94 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
There are next changes:
66

7+
## 1.2.14
8+
9+
There are next changes:
10+
11+
- added method-used-apps.json
12+
713
## 1.2.13
814

915
There are next changes:

src/Badoo/LiveProfilerUI/Pages/AjaxPages.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,46 @@
1010
use Badoo\LiveProfilerUI\DataProviders\Interfaces\SourceInterface;
1111
use Badoo\LiveProfilerUI\DataProviders\Interfaces\JobInterface;
1212
use Badoo\LiveProfilerUI\DataProviders\Interfaces\MethodInterface;
13+
use Badoo\LiveProfilerUI\DataProviders\Interfaces\MethodDataInterface;
1314
use Badoo\LiveProfilerUI\DataProviders\Interfaces\SnapshotInterface;
15+
use Badoo\LiveProfilerUI\FieldList;
1416

1517
class AjaxPages
1618
{
1719
/** @var SnapshotInterface */
1820
protected $Snapshot;
1921
/** @var MethodInterface */
2022
protected $Method;
23+
/** @var MethodDataInterface */
24+
protected $MethodData;
2125
/** @var JobInterface */
2226
protected $Job;
2327
/** @var Aggregator */
2428
protected $Aggregator;
2529
/** @var SourceInterface */
2630
protected $Source;
31+
/** @var FieldList */
32+
protected $FieldList;
2733
/** @var bool */
2834
protected $use_jobs;
2935

3036
public function __construct(
3137
SnapshotInterface $Snapshot,
3238
MethodInterface $Method,
39+
MethodDataInterface $MethodData,
3340
JobInterface $Job,
3441
Aggregator $Aggregator,
3542
SourceInterface $Source,
43+
FieldList $FieldList,
3644
bool $use_jobs = false
3745
) {
3846
$this->Snapshot = $Snapshot;
3947
$this->Method = $Method;
48+
$this->MethodData = $MethodData;
4049
$this->Job = $Job;
4150
$this->Aggregator = $Aggregator;
4251
$this->Source = $Source;
52+
$this->FieldList = $FieldList;
4353
$this->use_jobs = $use_jobs;
4454
}
4555

@@ -160,6 +170,63 @@ public function searchMethods(string $term) : array
160170
}
161171
}
162172

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+
163230
public function allMethods() : array
164231
{
165232
try {

src/config/services.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ services:
103103

104104
ajax_pages:
105105
class: \Badoo\LiveProfilerUI\Pages\AjaxPages
106-
arguments: ['@snapshot', '@method', '@job', '@aggregator', '@source', '%aggregator.use_jobs_in_aggregation%']
106+
arguments: ['@snapshot', '@method', '@method_data', '@job', '@aggregator', '@source', '@fields', '%aggregator.use_jobs_in_aggregation%']
107107

108108
# services for data providers
109109
snapshot:

src/www/index.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,16 @@
127127
echo json_encode($result);
128128
break;
129129

130+
case '/profiler/method-used-apps.json':
131+
$method = isset($_GET['method']) ? trim($_GET['method']) : '';
132+
header('Content-Type: application/json;charset=UTF-8');
133+
134+
/** @var \Badoo\LiveProfilerUI\Pages\AjaxPages $Page */
135+
$Page = $App->getPage('ajax_pages');
136+
137+
echo json_encode($Page->getMethodUsedApps($method));
138+
break;
139+
130140
case '/profiler/all-methods.json':
131141
header('Content-Type: application/json;charset=UTF-8');
132142

tests/unit/Badoo/LiveProfilerUI/Pages/AjaxPagesTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,12 @@ public function testConstruct()
476476
->setMethods()
477477
->getMock();
478478

479+
/** @var \Badoo\LiveProfilerUI\DataProviders\MethodData $MethodDataMock */
480+
$MethodDataMock = $this->getMockBuilder(\Badoo\LiveProfilerUI\DataProviders\MethodData::class)
481+
->disableOriginalConstructor()
482+
->setMethods([])
483+
->getMock();
484+
479485
/** @var \Badoo\LiveProfilerUI\DataProviders\Job $JobMock */
480486
$JobMock = $this->getMockBuilder(\Badoo\LiveProfilerUI\DataProviders\Job::class)
481487
->disableOriginalConstructor()
@@ -494,14 +500,18 @@ public function testConstruct()
494500
->setMethods()
495501
->getMock();
496502

503+
$FieldList = new \Badoo\LiveProfilerUI\FieldList(['wt'], ['min', 'max', 'percent'], []);
504+
497505
$use_jobs = true;
498506

499507
$Page = new \Badoo\LiveProfilerUI\Pages\AjaxPages(
500508
$SnapshotMock,
501509
$MethodMock,
510+
$MethodDataMock,
502511
$JobMock,
503512
$AggregatorMock,
504513
$SourceMock,
514+
$FieldList,
505515
$use_jobs
506516
);
507517

0 commit comments

Comments
 (0)