mirror of
https://github.com/danog/TelegramApiServer.git
synced 2024-11-30 04:19:13 +01:00
Revert bulk aggreagation
This commit is contained in:
parent
6ef7a898ab
commit
0ad5d07d94
12
composer.lock
generated
12
composer.lock
generated
@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "b9e9ba3184bce93fe3654528621101f4",
|
||||
"content-hash": "dc5798d52e4ed25349fd1c90bf88660d",
|
||||
"packages": [
|
||||
{
|
||||
"name": "amphp/amp",
|
||||
@ -232,7 +232,7 @@
|
||||
"version": "2.x-dev",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/xtrime-ru/dns.git",
|
||||
"url": "git@github.com:xtrime-ru/dns.git",
|
||||
"reference": "037b762d95f7d9e855b9c6736c0ccc4adcb8921e"
|
||||
},
|
||||
"dist": {
|
||||
@ -323,10 +323,7 @@
|
||||
"dns",
|
||||
"resolve"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/xtrime-ru/dns/tree/2.x"
|
||||
},
|
||||
"time": "2024-05-14T18:13:22+00:00"
|
||||
"time": "2024-05-14T16:09:55+00:00"
|
||||
},
|
||||
{
|
||||
"name": "amphp/file",
|
||||
@ -6889,7 +6886,8 @@
|
||||
"platform": {
|
||||
"php": "^8.2",
|
||||
"ext-json": "*",
|
||||
"ext-mbstring": "*"
|
||||
"ext-mbstring": "*",
|
||||
"ext-curl": "*"
|
||||
},
|
||||
"platform-dev": [],
|
||||
"plugin-api-version": "2.6.0"
|
||||
|
@ -5,6 +5,10 @@ namespace TelegramApiServer\Controllers;
|
||||
use Exception;
|
||||
use TelegramApiServer\Client;
|
||||
use TelegramApiServer\Config;
|
||||
use TelegramApiServer\Logger;
|
||||
use function Amp\async;
|
||||
use function Amp\delay;
|
||||
use function Amp\Future\awaitAll;
|
||||
|
||||
final class ApiController extends AbstractApiController
|
||||
{
|
||||
@ -34,6 +38,36 @@ final class ApiController extends AbstractApiController
|
||||
return $this->callApiCommon($madelineProto);
|
||||
}
|
||||
|
||||
return $this->callApiCommon($madelineProto);
|
||||
//GROUP REQUESTS IN BULKS
|
||||
static $futures = [];
|
||||
|
||||
$futures[] = $future = async($this->callApiCommon(...), $madelineProto);
|
||||
delay($this->waitNextTick());
|
||||
|
||||
if ($futures) {
|
||||
awaitAll($futures);
|
||||
Logger::getInstance()->notice("Executed bulk requests:" . count($futures));
|
||||
$futures = [];
|
||||
}
|
||||
|
||||
return $future->await();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sync threads execution via time ticks
|
||||
* Need to enable madelineProto futures bulk execution
|
||||
* @param float $tick interval of execution in seconds.
|
||||
*/
|
||||
protected function waitNextTick(float $tick = 0.5): float {
|
||||
$tickMs = (int)($tick * 1000);
|
||||
$now = (int)(microtime(true) * 1000);
|
||||
$currentTick = intdiv((int)(microtime(true) * 1000), $tickMs);
|
||||
$nextTick = ($currentTick + 1);
|
||||
$nextTickTime = $nextTick * $tickMs;
|
||||
$wait = round(($nextTickTime - $now)/1000, 3);
|
||||
|
||||
Logger::getInstance()->notice("Waiting $wait seconds before tick");
|
||||
|
||||
return $wait;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user