Skip to content

Commit

Permalink
Merge pull request #72 from openstreetmap-polska/dev
Browse files Browse the repository at this point in the history
Release to main
  • Loading branch information
Zaczero authored Apr 5, 2024
2 parents 752b14f + 6a8f9f7 commit b5c8fdd
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
16 changes: 13 additions & 3 deletions config/postgres.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,21 @@
# reason: unused, improved compatibility
unix_socket_directories = ''

# increase max connections
max_connections = 1000

# adjust memory usage
shared_buffers = 512MB
effective_cache_size = 1GB

# increase max connections
max_connections = 1000

# detect disconnected clients
# reason: safeguard resource usage
client_connection_check_interval = 5s

# disconnect idle clients with open transactions
# reason: safeguard resource usage
idle_in_transaction_session_timeout = 5min

# disable replication and reduce WAL usage
# reason: unused, reduced resource usage
wal_level = minimal
Expand Down Expand Up @@ -46,6 +54,8 @@ random_page_cost = 1.1

# increase logging verbosity
# reason: useful for development
log_connections = on
log_disconnections = on
log_lock_waits = on
log_temp_files = 0 # == log all temp files

Expand Down
2 changes: 2 additions & 0 deletions db.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
echo_pool=POSTGRES_LOG,
json_deserializer=JSON_DECODE,
json_serializer=lambda x: JSON_ENCODE(x).decode(),
pool_size=8,
max_overflow=-1,
query_cache_size=128,
)

Expand Down
4 changes: 2 additions & 2 deletions models/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def process(value: Point | None):
return None

x, y = get_coordinates(value)[0]
return f'SRID=4326;POINT({x} {y})' # WKT
return f'POINT({x} {y})' # WKT

return process

Expand Down Expand Up @@ -50,7 +50,7 @@ def process(value: Polygon | MultiPolygon | None):
if value is None:
return None

return 'SRID=4326;' + value.wkt
return value.wkt

return process

Expand Down
4 changes: 2 additions & 2 deletions services/aed_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ async def get_intersecting(
cls, bbox_or_geom: BBox | BaseGeometry, group_eps: float | None
) -> Sequence[AED | AEDGroup]:
geometry = bbox_or_geom.to_polygon() if isinstance(bbox_or_geom, BBox) else bbox_or_geom
geometry_wkt = 'SRID=4326;' + geometry.wkt
geometry_wkt = geometry.wkt

async with db_read() as session:
stmt = select(AED).where(func.ST_Intersects(AED.position, func.ST_GeomFromEWKT(geometry_wkt)))
stmt = select(AED).where(func.ST_Intersects(AED.position, func.ST_GeomFromText(geometry_wkt, 4326)))
aeds = (await session.scalars(stmt)).all()

if len(aeds) <= 1 or group_eps is None:
Expand Down
4 changes: 2 additions & 2 deletions services/country_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ async def get_all() -> Sequence[Country]:
@trace
async def get_intersecting(cls, bbox_or_geom: BBox | Point) -> Sequence[Country]:
geometry = bbox_or_geom.to_polygon() if isinstance(bbox_or_geom, BBox) else bbox_or_geom
geometry_wkt = 'SRID=4326;' + geometry.wkt
geometry_wkt = geometry.wkt

async with db_read() as session:
stmt = select(Country).where(func.ST_Intersects(Country.geometry, func.ST_GeomFromEWKT(geometry_wkt)))
stmt = select(Country).where(func.ST_Intersects(Country.geometry, func.ST_GeomFromText(geometry_wkt, 4326)))
return (await session.scalars(stmt)).all()


Expand Down

0 comments on commit b5c8fdd

Please sign in to comment.