places-setup: make transaction size configurable (fix #943)
Signed-off-by: Varun Patil <radialapps@gmail.com>pull/1010/head
parent
0e42e55333
commit
4aaf6c32a2
|
@ -44,6 +44,7 @@ class PlacesSetup extends Command
|
||||||
->setName('memories:places-setup')
|
->setName('memories:places-setup')
|
||||||
->setDescription('Setup reverse geocoding')
|
->setDescription('Setup reverse geocoding')
|
||||||
->addOption('recalculate', 'r', InputOption::VALUE_NONE, 'Only recalculate places for existing files')
|
->addOption('recalculate', 'r', InputOption::VALUE_NONE, 'Only recalculate places for existing files')
|
||||||
|
->addOption('transaction-size', null, InputOption::VALUE_REQUIRED, 'Reduce this value if your database crashes', 50)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,6 +53,12 @@ class PlacesSetup extends Command
|
||||||
$this->output = $output;
|
$this->output = $output;
|
||||||
$recalculate = $input->getOption('recalculate');
|
$recalculate = $input->getOption('recalculate');
|
||||||
|
|
||||||
|
if (($this->places->txnSize = (int) $input->getOption('transaction-size')) < 1) {
|
||||||
|
$this->output->writeln('<error>Transaction size must be at least 1</error>');
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
$this->output->writeln('Attempting to set up reverse geocoding');
|
$this->output->writeln('Attempting to set up reverse geocoding');
|
||||||
|
|
||||||
// Detect the GIS type
|
// Detect the GIS type
|
||||||
|
|
|
@ -13,12 +13,16 @@ const GIS_TYPE_NONE = 0;
|
||||||
const GIS_TYPE_MYSQL = 1;
|
const GIS_TYPE_MYSQL = 1;
|
||||||
const GIS_TYPE_POSTGRES = 2;
|
const GIS_TYPE_POSTGRES = 2;
|
||||||
const APPROX_PLACES = 635189;
|
const APPROX_PLACES = 635189;
|
||||||
const DB_TRANSACTION_SIZE = 50;
|
|
||||||
|
|
||||||
const PLANET_URL = 'https://github.com/pulsejet/memories-assets/releases/download/geo-0.0.3/planet_coarse_boundaries.zip';
|
const PLANET_URL = 'https://github.com/pulsejet/memories-assets/releases/download/geo-0.0.3/planet_coarse_boundaries.zip';
|
||||||
|
|
||||||
class Places
|
class Places
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Number of places to process in a single transaction.
|
||||||
|
*/
|
||||||
|
public int $txnSize = 50;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
protected IConfig $config,
|
protected IConfig $config,
|
||||||
protected IDBConnection $connection,
|
protected IDBConnection $connection,
|
||||||
|
@ -240,7 +244,7 @@ class Places
|
||||||
|
|
||||||
// Function to commit the current transaction
|
// Function to commit the current transaction
|
||||||
$transact = function () use (&$txnCount): void {
|
$transact = function () use (&$txnCount): void {
|
||||||
if (++$txnCount >= DB_TRANSACTION_SIZE) {
|
if (++$txnCount >= $this->txnSize) {
|
||||||
$this->connection->commit();
|
$this->connection->commit();
|
||||||
$this->connection->beginTransaction();
|
$this->connection->beginTransaction();
|
||||||
$txnCount = 0;
|
$txnCount = 0;
|
||||||
|
|
Loading…
Reference in New Issue