Skip to content

Commit

Permalink
HP-1894: poll requests implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
tafid committed Jun 13, 2024
1 parent 888f25f commit a066ca0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public function isRaw()
return !empty($this->query->options['raw']);
}

protected function getHandler()
public function getHandler()
{
$handler = $this->getDb()->getHandler();
if ($handler === null) {
Expand Down
20 changes: 20 additions & 0 deletions src/ActiveDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

namespace hiqdev\hiart;

use yii\base\InvalidConfigException;
use yii\db\QueryInterface;

class ActiveDataProvider extends \yii\data\ActiveDataProvider
{
/**
Expand Down Expand Up @@ -52,4 +55,21 @@ public function refresh(bool $keepTotalCount = false): void
$this->setTotalCount($tc);
}
}

public function prepareQuery(): QueryInterface
{
if (!$this->query instanceof QueryInterface) {
throw new InvalidConfigException('The "query" property must be an instance of a class that implements the QueryInterface e.g. yii\db\Query or its subclasses.');
}
$query = clone $this->query;
if (($pagination = $this->getPagination()) !== false) {
$pagination->totalCount = $this->getTotalCount();
$query->limit($pagination->getLimit())->offset($pagination->getOffset());
}
if (($sort = $this->getSort()) !== false) {
$query->addOrderBy($sort->getOrders());
}

return $query;
}
}
32 changes: 15 additions & 17 deletions src/debug/DebugPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Yii;
use yii\base\ViewContextInterface;
use yii\debug\Panel;
use yii\helpers\ArrayHelper;
use yii\log\Logger;

/**
Expand Down Expand Up @@ -49,7 +50,7 @@ public function getSummary()
}

return $this->render('summary', [
'url' => $this->getUrl(),
'url' => $this->getUrl(),
'count' => count($timings),
'total' => number_format($total * 1000) . ' ms',
]);
Expand Down Expand Up @@ -81,23 +82,20 @@ public function calculateTimings()
$messages = $this->data['messages'];
$timings = [];
$stack = [];
foreach ($messages as $i => $log) {
[$token, $level, $category, $timestamp] = $log;
$log[5] = $i;
if ($level === Logger::LEVEL_PROFILE_BEGIN) {
$stack[] = $log;
} elseif ($level === Logger::LEVEL_PROFILE_END) {
$last = array_pop($stack);
if ($last !== null && $last[0] === $token) {
$timings[$last[5]] = [count($stack), $token, $last[3], $timestamp - $last[3], $last[4]];
}
$groups = ArrayHelper::index($messages, 1, 0);
foreach ($groups as $token => $logs) {
if (count($logs) !== 2) {
continue;
}
}

$now = microtime(true);
while (($last = array_pop($stack)) !== null) {
$delta = $now - $last[3];
$timings[$last[5]] = [count($stack), $last[0], $last[2], $delta, $last[4]];
$begin = $logs[Logger::LEVEL_PROFILE_BEGIN];
$end = $logs[Logger::LEVEL_PROFILE_END];
$timings[$begin[5]] = [
count($stack),
$token,
$end[3],
$end[3] - $begin[3],
$begin[4],
];
}
ksort($timings);

Expand Down

0 comments on commit a066ca0

Please sign in to comment.