Fix serialization

This commit is contained in:
Daniil Gentili 2020-09-28 11:56:14 +02:00
parent a6b4c0f5cf
commit f5e4d29db1
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
5 changed files with 22 additions and 11 deletions

View File

@ -187,9 +187,9 @@ class API extends InternalDoc
protected function connectToMadelineProto(SettingsAbstract $settings, bool $forceFull = false): \Generator
{
if ($settings instanceof SettingsIpc) {
$forceFull = $forceFull || $settings->getForceFull();
$forceFull = $forceFull || $settings->getSlow();
} elseif ($settings instanceof Settings) {
$forceFull = $forceFull || $settings->getIpc()->getForceFull();
$forceFull = $forceFull || $settings->getIpc()->getSlow();
}
[$unserialized, $this->unlock] = yield Tools::timeoutWithDefault(

View File

@ -125,7 +125,7 @@ final class APIWrapper
*/
public static function __sleep(): array
{
return ['API', 'webApiTemplate', 'gettingApiId', 'myTelegramOrgWrapper', 'storage', 'lua']; //, 'async'];
return ['API', 'webApiTemplate', 'gettingApiId', 'myTelegramOrgWrapper', 'storage', 'lua'];
}
/**

View File

@ -159,6 +159,15 @@ abstract class AbstractAPIFactory extends AsyncConstruct
}
return $res;
}
/**
* Sleep function.
*
* @return array
*/
public function __sleep()
{
return [];
}
/**
* Call async wrapper function.
*

View File

@ -97,7 +97,7 @@ use danog\MadelineProto\Tools;
Magic::classExists();
Magic::$script_cwd = $_GET['cwd'] ?? Magic::getcwd();
$API = new API($ipcPath, (new Ipc)->setForceFull(true));
$API = new API($ipcPath, (new Ipc)->setSlow(true));
$API->init();
$API->initSelfRestart();

View File

@ -11,7 +11,7 @@ class Ipc extends SettingsAbstract
*
* WARNING: this will cause slow startup if enabled.
*/
protected bool $forceFull = false;
protected bool $slow = false;
public function mergeArray(array $settings): void
{
@ -22,21 +22,23 @@ class Ipc extends SettingsAbstract
*
* @return bool
*/
public function getForceFull(): bool
public function getSlow(): bool
{
return $this->forceFull;
return $this->slow;
}
/**
* Set WARNING: this will cause slow startup if enabled.
* Whether to force full deserialization of instance, without using the IPC server/client.
*
* WARNING: this will cause slow startup if enabled.
*
* @param bool $forceFull WARNING: this will cause slow startup if enabled.
* @param bool $slow WARNING: this will cause slow startup if enabled.
*
* @return self
*/
public function setForceFull(bool $forceFull): self
public function setSlow(bool $slow): self
{
$this->forceFull = $forceFull;
$this->slow = $slow;
return $this;
}