mirror of
https://github.com/danog/MadelineProto.git
synced 2024-11-27 07:34:41 +01:00
Execute migration just once
This commit is contained in:
parent
1ed51dd7fa
commit
6b5d7ad909
@ -928,10 +928,6 @@ final class MTProto implements TLCallback, LoggerGetter
|
||||
*/
|
||||
private function upgradeMadelineProto(): void
|
||||
{
|
||||
if (isset($this->hook_url) && \is_string($this->hook_url)) {
|
||||
$this->webhookUrl = $this->hook_url;
|
||||
}
|
||||
|
||||
$this->logger->logger(Lang::$current_lang['serialization_ofd'], Logger::WARNING);
|
||||
foreach ($this->datacenter->getDataCenterConnections() as $dc_id => $socket) {
|
||||
if ($this->authorized === API::LOGGED_IN && \is_int($dc_id) && $socket->hasPermAuthKey() && $socket->hasTempAuthKey()) {
|
||||
@ -956,21 +952,6 @@ final class MTProto implements TLCallback, LoggerGetter
|
||||
} catch (RPCErrorException $e) {
|
||||
}
|
||||
}
|
||||
|
||||
async(function (): void {
|
||||
$counter = 0;
|
||||
foreach ($this->chats as $id => $chat) {
|
||||
$id = (int) $id;
|
||||
$counter ++;
|
||||
if ($counter % 1000 === 0) {
|
||||
$this->logger->logger("Upgrading chats: $counter", Logger::WARNING);
|
||||
}
|
||||
|
||||
if (!($chat['min'] ?? false)) {
|
||||
$this->minDatabase->clearPeer($id);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Post-deserialization initialization function.
|
||||
|
@ -61,6 +61,11 @@ final class MinDatabase implements TLCallback
|
||||
*
|
||||
*/
|
||||
private bool $clean = false;
|
||||
/**
|
||||
* Whether we synced ourselves with the peer database.
|
||||
*
|
||||
*/
|
||||
private bool $synced = false;
|
||||
|
||||
/**
|
||||
* List of properties stored in database (memory or external).
|
||||
@ -77,7 +82,7 @@ final class MinDatabase implements TLCallback
|
||||
}
|
||||
public function __sleep()
|
||||
{
|
||||
return ['db', 'API', 'clean'];
|
||||
return ['db', 'API', 'clean', 'synced'];
|
||||
}
|
||||
public function init(): void
|
||||
{
|
||||
@ -85,17 +90,33 @@ final class MinDatabase implements TLCallback
|
||||
if (!$this->API->getSettings()->getDb()->getEnableMinDb()) {
|
||||
$this->db->clear();
|
||||
}
|
||||
if ($this->clean) {
|
||||
return;
|
||||
}
|
||||
EventLoop::queue(function (): void {
|
||||
foreach ($this->db as $id => $origin) {
|
||||
if (!isset($origin['peer']) || $origin['peer'] === $id) {
|
||||
unset($this->db[$id]);
|
||||
if (!$this->clean) {
|
||||
EventLoop::queue(function (): void {
|
||||
foreach ($this->db as $id => $origin) {
|
||||
if (!isset($origin['peer']) || $origin['peer'] === $id) {
|
||||
unset($this->db[$id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->clean = true;
|
||||
});
|
||||
$this->clean = true;
|
||||
});
|
||||
}
|
||||
if (!$this->synced) {
|
||||
EventLoop::queue(function (): void {
|
||||
$counter = 0;
|
||||
foreach ($this->API->chats as $id => $chat) {
|
||||
$id = (int) $id;
|
||||
$counter++;
|
||||
if ($counter % 1000 === 0) {
|
||||
$this->API->logger->logger("Upgrading chats: $counter", Logger::WARNING);
|
||||
}
|
||||
|
||||
if (!($chat['min'] ?? false)) {
|
||||
$this->clearPeer($id);
|
||||
}
|
||||
}
|
||||
$this->synced = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
public function getMethodAfterResponseDeserializationCallbacks(): array
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user