diff --git a/cerulean_cloud/cloud_function_ais_analysis/requirements.txt b/cerulean_cloud/cloud_function_ais_analysis/requirements.txt index 1ec81903..03442cba 100644 --- a/cerulean_cloud/cloud_function_ais_analysis/requirements.txt +++ b/cerulean_cloud/cloud_function_ais_analysis/requirements.txt @@ -10,4 +10,5 @@ scipy==1.8.0 shapely==2.0.1 Flask>=1.0,<3.0 functions-framework==3.0.0 -geoalchemy2 \ No newline at end of file +geoalchemy2 +asyncpg \ No newline at end of file diff --git a/cerulean_cloud/database_client.py b/cerulean_cloud/database_client.py index 0c9fa3f0..4cbf7e78 100644 --- a/cerulean_cloud/database_client.py +++ b/cerulean_cloud/database_client.py @@ -5,7 +5,7 @@ from dateutil.parser import parse from geoalchemy2.shape import from_shape from shapely.geometry import MultiPolygon, Polygon, box, shape -from sqlalchemy import select +from sqlalchemy import and_, select from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine import cerulean_cloud.database_schema as db @@ -182,15 +182,22 @@ async def get_slicks_without_sources_from_scene_id(self, scene_id, active=True): - It joins multiple tables: `db.Slick`, `db.SlickToSource`, `db.OrchestratorRun`, and `db.Sentinel1Grd`. - The query uses an outer join to filter out slicks that have associated sources. """ - return ( - self.session.query(db.Slick) + + query = ( + select(db.Slick) .outerjoin(db.SlickToSource, db.Slick.id == db.SlickToSource.slick) - .filter(db.SlickToSource.slick is None) .join(db.OrchestratorRun) .join(db.Sentinel1Grd) - .filter(db.Sentinel1Grd.id == scene_id, db.Slick.active == active) - .all() + .where( + and_( + db.SlickToSource.slick is None, + db.Sentinel1Grd.scene_id == scene_id, + db.Slick.active == active, + ) + ) ) + result = await self.session.execute(query) + return result.scalars().all() async def get_scene_from_id(self, scene_id): """