Skip to content

Commit

Permalink
places: fix postgres lookup
Browse files Browse the repository at this point in the history
Signed-off-by: Varun Patil <radialapps@gmail.com>
  • Loading branch information
pulsejet committed Mar 11, 2024
1 parent 00f1a97 commit d5400d7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.


- **Important**: You must run `occ memories:places-setup` again after this update
- Reverse geocoding lookups with Postgres/MySQL (not MariaDB) are now 100x faster
- Hide files starting with `.` in the timeline
- Prevent automatically retrying failed indexing jobs
- Support for 3GP videos ([#1055](https://github.com/pulsejet/memories/issues/1055))
Expand Down
7 changes: 5 additions & 2 deletions lib/Service/Places.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ public function queryPoint(float $lat, float $lon): array
if (GIS_TYPE_MYSQL === $gisType) {
$where = "ST_Contains(geometry, ST_GeomFromText('POINT({$lat} {$lon})', 4326))";
} elseif (GIS_TYPE_POSTGRES === $gisType) {
$where = "POINT('{$lat},{$lon}') <@ geometry";
// Postgres does not support using an index with POINT <@ POLYGON
// https://www.postgresql.org/docs/current/gist-builtin-opclasses.html
$where = "POLYGON('{$lat},{$lon}') <@ geometry";
} else {
return [];
}
Expand Down Expand Up @@ -456,7 +458,8 @@ protected function setupDatabase(int $gis): void
if (GIS_TYPE_MYSQL === $gis) {
$this->connection->executeQuery('CREATE SPATIAL INDEX planet_osm_polygon_geometry_idx ON memories_planet_geometry (geometry);');
} elseif (GIS_TYPE_POSTGRES === $gis) {
$this->connection->executeQuery('CREATE INDEX planet_osm_polygon_geometry_idx ON memories_planet_geometry USING GIST (geometry);');
// https://www.postgresql.org/docs/current/gist-builtin-opclasses.html
$this->connection->executeQuery('CREATE INDEX planet_osm_polygon_geometry_idx ON memories_planet_geometry USING GIST (geometry poly_ops);');
}
} catch (\Exception $e) {
throw new \Exception('Failed to create database tables: '.$e->getMessage());
Expand Down

0 comments on commit d5400d7

Please sign in to comment.