generated from spatie/package-skeleton-laravel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
last checkpoint: include cities in the nested set model calculation
Previously, the contents of the country files were read and inserted into the database in chunks of 1000. Then the Nested Set Model is built by reading the hierarchy.txt file and updating the records in the database(slow). At this point, the Nested Set Model is built first by reading the hierarchy.txt file, and combining it with the contents of the admin2Codes.txt file which contains the hierarchy for cities(Even though geonames.org has up to ADM5 division, it cuts-off at ADM2 for cities). After the nestedSet is built, the country files contents is mapped into a Geoname with the nestedSet properties(_lft, _rgt, depth and parent_id) and inserted into the database
- Loading branch information
Showing
10 changed files
with
370 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Parables\Geo\Actions; | ||
|
||
use Illuminate\Support\LazyCollection; | ||
use Parables\Geo\Actions\Concerns\HasToastable; | ||
|
||
class ReadFilesAction | ||
{ | ||
use HasToastable; | ||
|
||
/** | ||
* @param array<int,string> $fileNames | ||
* @return LazyCollection<int, LazyCollection> | ||
*/ | ||
public function execute(array $fileNames): LazyCollection | ||
{ | ||
$readFileAction = (new ReadFileAction)->toastable($this->toastable); | ||
|
||
return LazyCollection::make(function () use ($fileNames, $readFileAction) { | ||
foreach ($fileNames as $fileName) { | ||
yield $readFileAction->execute($fileName); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Parables\Geo\Actions; | ||
|
||
use Illuminate\Support\Arr; | ||
use Illuminate\Support\LazyCollection; | ||
use Parables\Geo\Actions\Concerns\HasToastable; | ||
use Parables\Geo\Actions\Fixtures\Toastable; | ||
|
||
it('can read a list of files into a LazyCollection of file contents', function () { | ||
$cacheFile = storage_path('/geo/countries.json'); | ||
$fileNames = array_map( | ||
fn ($fileName) => $fileName . '.txt', | ||
array_keys(Arr::wrap(json_decode(file_get_contents($cacheFile), associative: true))) | ||
); | ||
$files = (new ReadFilesAction)->toastable(new Toastable)->execute($fileNames); | ||
|
||
expect($files->count())->toBe(253); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.