This commit is contained in:
Daniil Gentili 2020-09-28 23:20:12 +02:00
parent db24e8e871
commit d792263e86
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
7 changed files with 18 additions and 6 deletions

View File

@ -92,7 +92,7 @@ $settings = [
],
'serialization' => [
'serialization_interval' => 30,
],
]
];
$MadelineProto = new API('bot.madeline', $settings);

View File

@ -32,6 +32,7 @@ abstract class DriverArray implements DbArray
}
abstract public function initConnection($settings): \Generator;
abstract public function initStartup(): \Generator;
/**
* @param self $new

View File

@ -35,7 +35,7 @@ class MemoryArray extends \ArrayIterator implements DbArray
if ($value instanceof DbArray) {
Logger::log("Loading database to memory. Please wait.", Logger::WARNING);
if ($value instanceof DriverArray) {
yield from $value->initConnection($value->dbSettings);
yield from $value->initStartup();
}
$value = yield $value->getArrayCopy();
}

View File

@ -16,7 +16,7 @@ use function Amp\call;
class RedisArray extends SqlArray
{
protected string $table;
public DatabaseRedis $dbSettings;
protected DatabaseRedis $dbSettings;
private RedisRedis $db;
// Legacy
@ -56,6 +56,7 @@ class RedisArray extends SqlArray
}
}
public function __sleep()
{
return ['table', 'dbSettings'];

View File

@ -19,6 +19,16 @@ abstract class SqlArray extends DriverArray
abstract protected function renameTable(string $from, string $to): \Generator;
/**
* Initialize on startup.
*
* @return \Generator
*/
public function initStartup(): \Generator
{
return $this->initConnection($this->dbSettings);
}
/**
* @param string $name
* @param DbArray|array|null $value
@ -49,7 +59,7 @@ abstract class SqlArray extends DriverArray
// Skip migrations if its same object
if ($instance !== $value) {
if ($value instanceof DriverArray) {
yield from $value->initConnection($value->dbSettings);
yield from $value->initStartup();
}
yield from static::renameTmpTable($instance, $value);
yield from static::migrateDataToDb($instance, $value);

View File

@ -194,7 +194,7 @@ abstract class Serialization
$unserialized = yield from $session->unserialize();
if ($unserialized instanceof DriverArray) {
Logger::log("Extracting session from database...");
yield from $unserialized->initConnection($unserialized->dbSettings);
yield from $unserialized->initStartup();
$unserialized = yield $unserialized['data'];
if (!$unserialized) {
throw new Exception("Could not extract session from database!");

View File

@ -29,7 +29,7 @@ class Ipc extends SettingsAbstract
/**
* Whether to force full deserialization of instance, without using the IPC server/client.
*
*
* WARNING: this will cause slow startup if enabled.
*
* @param bool $slow WARNING: this will cause slow startup if enabled.