Skip to content

Commit

Permalink
places-setup: make transaction size configurable (fix #943)
Browse files Browse the repository at this point in the history
Signed-off-by: Varun Patil <radialapps@gmail.com>
  • Loading branch information
pulsejet committed Jan 5, 2024
1 parent 0e42e55 commit 4aaf6c3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 7 additions & 0 deletions lib/Command/PlacesSetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ protected function configure(): void
->setName('memories:places-setup')
->setDescription('Setup reverse geocoding')
->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)
;
}

Expand All @@ -52,6 +53,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->output = $output;
$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');

// Detect the GIS type
Expand Down
8 changes: 6 additions & 2 deletions lib/Service/Places.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@
const GIS_TYPE_MYSQL = 1;
const GIS_TYPE_POSTGRES = 2;
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';

class Places
{
/**
* Number of places to process in a single transaction.
*/
public int $txnSize = 50;

public function __construct(
protected IConfig $config,
protected IDBConnection $connection,
Expand Down Expand Up @@ -240,7 +244,7 @@ public function importPlanet(string $datafile): void

// Function to commit the current transaction
$transact = function () use (&$txnCount): void {
if (++$txnCount >= DB_TRANSACTION_SIZE) {
if (++$txnCount >= $this->txnSize) {
$this->connection->commit();
$this->connection->beginTransaction();
$txnCount = 0;
Expand Down

0 comments on commit 4aaf6c3

Please sign in to comment.