Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add mosaic search + other updates #36

Merged
merged 8 commits into from
Mar 10, 2022
Merged

add mosaic search + other updates #36

merged 8 commits into from
Mar 10, 2022

Conversation

vincentsarago
Copy link
Member

This PR adds a mosaic/list endpoint to list/search mosaic registered in PgSTAC database

ref:

Other fix/additions

breaking changes

  • add CDK_ prefix to deployment related environment variables

@@ -99,7 +100,7 @@ class Config:
"""model config"""

env_file = "deployment/.env"
env_prefix = "EOAPI_RASTER_"
env_prefix = "CDK_EOAPI_RASTER_"
Copy link
Member Author

Choose a reason for hiding this comment

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

This is to avoid confusion between EOAPI_RASTER_ env used in eoAPI.raster module and the ones used for deployment.

) as conn:
conn.execute(
sql.SQL(
"CREATE INDEX IF NOT EXISTS searches_mosaic ON searches ((true)) WHERE metadata->>'type'='mosaic';"
Copy link
Member Author

Choose a reason for hiding this comment

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

By default we create an index on search metadata->>type (to be able to list mosaic)
cc @bitner

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's ok to have this here for now, but I think that it would be good to just include this index in pgstac itself and get rid of this in the future as this will add a bit of latency every time you connect.

Copy link
Member Author

Choose a reason for hiding this comment

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

this is only used when we create the database!

@@ -85,6 +85,8 @@ services:
# AWS S3 endpoint config
- AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
- AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
# API Config
- EOAPI_RASTER_ENABLE_MOSAIC_SEARCH=TRUE
Copy link
Member Author

Choose a reason for hiding this comment

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

⚠️ for now this is not set in the CDK code

links=links,
numberMatched=int(nb_items),
numberReturned=len(searches_info),
)
Copy link
Member Author

Choose a reason for hiding this comment

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

@bitner can you check that I'm not doing any stupid SQL (or python, or general) stuff.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nothing bad here that needs to change to merge, but some suggestions on best practices above.

@@ -73,6 +73,7 @@ class eoRasterSettings(pydantic.BaseSettings):
"CPL_VSIL_CURL_ALLOWED_EXTENSIONS": ".tif,.TIF,.tiff",
"GDAL_CACHEMAX": "200", # 200 mb
"GDAL_DISABLE_READDIR_ON_OPEN": "EMPTY_DIR",
"GDAL_INGESTED_BYTES_AT_OPEN": "32768",
Copy link
Member Author

Choose a reason for hiding this comment

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

I think this is a reasonable default value

@bitner
Copy link
Contributor

bitner commented Mar 4, 2022 via email

@vincentsarago vincentsarago requested a review from bitner March 7, 2022 11:06
Copy link
Contributor

@bitner bitner left a comment

Choose a reason for hiding this comment

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

I left a couple comments about some best practices for constructing sql. None of them are critical, but things to keep in mind.

The thing I might consider changing now is to use the same object for context as is in the spec for search for consistency.

We should definitely follow up and make sure we just add that index for search metadata directly into pgstac so we can get rid of it here in the future.

) as conn:
conn.execute(
sql.SQL(
"CREATE INDEX IF NOT EXISTS searches_mosaic ON searches ((true)) WHERE metadata->>'type'='mosaic';"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's ok to have this here for now, but I think that it would be good to just include this index in pgstac itself and get rid of this in the future as this will add a bit of latency every time you connect.

src/eoapi/raster/eoapi/raster/factory.py Outdated Show resolved Hide resolved
):
"""List a Search query."""
offset_and_limit = [
sql.SQL("LIMIT {number}").format(number=sql.Literal(limit)),
Copy link
Contributor

Choose a reason for hiding this comment

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

This is OK from a SQL injection standpoint, but in general we should avoid using sql.Literal(). Literals should be put in the query as placeholders and the values passed as parameters to execute ie execute("select * from search limit %(limit)s" , {"limit":limit}). This allows psycopg to use prepared statements behind the scenes which adds a bit more security and potential performance benefits.

src/eoapi/raster/eoapi/raster/factory.py Outdated Show resolved Hide resolved
links=links,
numberMatched=int(nb_items),
numberReturned=len(searches_info),
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nothing bad here that needs to change to merge, but some suggestions on best practices above.

@vincentsarago vincentsarago merged commit 2c8b8b1 into master Mar 10, 2022
@vincentsarago vincentsarago deleted the MosaicSearch branch March 10, 2022 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants