Skip to content

Commit

Permalink
Merge pull request #128 from stac-utils/PgSTACDepsAndPoolCheck
Browse files Browse the repository at this point in the history
add database pool check and more params in dependency
  • Loading branch information
vincentsarago authored Oct 10, 2023
2 parents 2ff16ee + 06af36f commit c339baf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Release Notes

## Unrelease

* add `pgstac_dependency` attribute in `MosaicTilerFactory` (defaults to `dependencies.PgSTACParams`)
* add database's `pool` check in startup event

## 0.8.0 (2023-10-06)

* update titiler requirement to `>=0.14.0,<0.15`
Expand Down
4 changes: 4 additions & 0 deletions titiler/pgstac/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ async def connect_to_db(
kwargs={"options": "-c search_path=pgstac,public -c application_name=pgstac"},
)

# Make sure the pool is ready
# ref: https://www.psycopg.org/psycopg3/docs/advanced/pool.html#pool-startup-check
app.state.dbpool.wait()


async def close_db_connection(app: FastAPI) -> None:
"""Close Pool."""
Expand Down
21 changes: 11 additions & 10 deletions titiler/pgstac/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class MosaicTilerFactory(BaseTilerFactory):

pixel_selection_dependency: Callable[..., MosaicMethodBase] = PixelSelectionParams

pgstac_dependency: Type[DefaultDependency] = PgSTACParams
backend_dependency: Type[DefaultDependency] = BackendParams

# Add/Remove some endpoints
Expand Down Expand Up @@ -217,7 +218,7 @@ def tile(
color_formula=Depends(ColorFormulaParams),
colormap=Depends(self.colormap_dependency),
render_params=Depends(self.render_dependency),
pgstac_params: PgSTACParams = Depends(),
pgstac_params=Depends(self.pgstac_dependency),
backend_params=Depends(self.backend_dependency),
reader_params=Depends(self.reader_dependency),
env=Depends(self.environment_dependency),
Expand Down Expand Up @@ -329,7 +330,7 @@ def tilejson(
color_formula=Depends(ColorFormulaParams),
colormap=Depends(self.colormap_dependency),
render_params=Depends(self.render_dependency),
pgstac_params: PgSTACParams = Depends(),
pgstac_params=Depends(self.pgstac_dependency),
backend_params=Depends(self.backend_dependency),
reader_params=Depends(self.reader_dependency),
):
Expand Down Expand Up @@ -431,7 +432,7 @@ def map_viewer(
color_formula=Depends(ColorFormulaParams),
colormap=Depends(self.colormap_dependency),
render_params=Depends(self.render_dependency),
pgstac_params: PgSTACParams = Depends(),
pgstac_params=Depends(self.pgstac_dependency),
backend_params=Depends(self.backend_dependency),
reader_params=Depends(self.reader_dependency),
env=Depends(self.environment_dependency),
Expand Down Expand Up @@ -523,7 +524,7 @@ def wmts(
self.rescale_dependency,
self.colormap_dependency,
self.render_dependency,
PgSTACParams,
self.pgstac_dependency,
self.reader_dependency,
self.backend_dependency,
]
Expand Down Expand Up @@ -639,7 +640,7 @@ def assets_for_tile(
Literal[tuple(self.supported_tms.list())],
f"Identifier selecting one of the TileMatrixSetId supported (default: '{self.default_tms}')",
] = self.default_tms,
pgstac_params: PgSTACParams = Depends(),
pgstac_params=Depends(self.pgstac_dependency),
backend_params=Depends(self.backend_dependency),
reader_params=Depends(self.reader_dependency),
):
Expand All @@ -663,7 +664,7 @@ def assets_for_point(
lat: Annotated[float, Path(description="Latitude")],
searchid=Depends(self.path_dependency),
coord_crs=Depends(CoordCRSParams),
pgstac_params: PgSTACParams = Depends(),
pgstac_params=Depends(self.pgstac_dependency),
backend_params=Depends(self.backend_dependency),
reader_params=Depends(self.reader_dependency),
):
Expand Down Expand Up @@ -754,7 +755,7 @@ def register_search(
self.rescale_dependency,
self.colormap_dependency,
self.render_dependency,
PgSTACParams,
self.pgstac_dependency,
self.reader_dependency,
self.backend_dependency,
]
Expand Down Expand Up @@ -1057,7 +1058,7 @@ def geojson_statistics(
pixel_selection=Depends(self.pixel_selection_dependency),
stats_params=Depends(self.stats_dependency),
histogram_params=Depends(self.histogram_dependency),
pgstac_params: PgSTACParams = Depends(),
pgstac_params=Depends(self.pgstac_dependency),
backend_params=Depends(self.backend_dependency),
reader_params=Depends(self.reader_dependency),
env=Depends(self.environment_dependency),
Expand Down Expand Up @@ -1137,7 +1138,7 @@ def bbox_image(
color_formula=Depends(ColorFormulaParams),
colormap=Depends(self.colormap_dependency),
render_params=Depends(self.render_dependency),
pgstac_params: PgSTACParams = Depends(),
pgstac_params=Depends(self.pgstac_dependency),
backend_params=Depends(self.backend_dependency),
reader_params=Depends(self.reader_dependency),
env=Depends(self.environment_dependency),
Expand Down Expand Up @@ -1212,7 +1213,7 @@ def feature_image(
color_formula=Depends(ColorFormulaParams),
colormap=Depends(self.colormap_dependency),
render_params=Depends(self.render_dependency),
pgstac_params: PgSTACParams = Depends(),
pgstac_params=Depends(self.pgstac_dependency),
backend_params=Depends(self.backend_dependency),
reader_params=Depends(self.reader_dependency),
env=Depends(self.environment_dependency),
Expand Down

1 comment on commit c339baf

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'TiTiler-pgSTAC Benchmarks'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.30.

Benchmark suite Current: c339baf Previous: 2ff16ee Ratio
.github/workflows/tests/benchmarks.py::test_benchmark_tile[3/5/0] 12.92289489714579 iter/sec (stddev: 0.005461343150587882) 17.02542364481147 iter/sec (stddev: 0.002687803411617809) 1.32
.github/workflows/tests/benchmarks.py::test_benchmark_tile[6/43/31] 15.071114507084953 iter/sec (stddev: 0.005686965951253884) 19.799747397323173 iter/sec (stddev: 0.0024947333490095477) 1.31

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.