-
Notifications
You must be signed in to change notification settings - Fork 27
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
♻️ Replace aiopg in catalog service #2869
♻️ Replace aiopg in catalog service #2869
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2869 +/- ##
========================================
- Coverage 79.1% 72.8% -6.4%
========================================
Files 673 674 +1
Lines 27602 27620 +18
Branches 3218 3220 +2
========================================
- Hits 21854 20117 -1737
- Misses 5001 6856 +1855
+ Partials 747 647 -100
Flags with carried forward coverage won't be shown. Click here to find out more.
|
1fa0a11
to
8647cbc
Compare
3ee44cd
to
7366d02
Compare
bddc27f
to
259e0c2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 very nice
from sqlalchemy.ext.asyncio import create_async_engine | ||
|
||
engine = create_async_engine( | ||
f"{postgres_db.url}".replace("postgresql", "postgresql+asyncpg") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this will stay in there until we fully remove aiopg. Maybe put a note.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the only location where the async engine is created (pytest-simcore package). but no worries, the PostgresSettings also have a special attribute that does it for you.
2d3be41
to
f5ec354
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice work. Just a few comments!
packages/postgres-database/src/simcore_postgres_database/utils_aiosqlalchemy.py
Outdated
Show resolved
Hide resolved
packages/postgres-database/src/simcore_postgres_database/utils_aiosqlalchemy.py
Outdated
Show resolved
Hide resolved
packages/postgres-database/src/simcore_postgres_database/utils_aiosqlalchemy.py
Show resolved
Hide resolved
packages/postgres-database/src/simcore_postgres_database/utils_aiosqlalchemy.py
Outdated
Show resolved
Hide resolved
@@ -21,12 +21,14 @@ fastapi[all] | |||
pydantic[dotenv] | |||
|
|||
# database | |||
aiopg[sa] | |||
asyncpg | |||
sqlalchemy[asyncio] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
two things, we already introduce this "extra"
sqlalchemy[postgresql_psycopg2binary]
should we always extra with both?
sqlalchemy[asyncio,postgresql_psycopg2binary]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no I think once we can fully migrate, the psycopg2binary becomes obsolete. maybe just for testing where we do have a sync engine as well
17f1eb8
to
b5b209b
Compare
What do these changes do?
This PR is following #2864 that updated SQLalchemy to the latest version and left the catalog service with some functional but suboptimal code such that aiopg could work with the newer SQLalchemy syntax.
This PR replaces aiopg/psycopg2 with asyncpg and allows a full integration with SQLalchemy ONLY in the catalog for now.
This PR also introduces the use of the library aiocache and is currently used to cache the list of services returned by the director-v0 for a small performance boost in listing the services according to service access rights. This library can also be used with redis to have a distributed cache.
Currently we list all the services with all the details, etc. The most time consuming part is creating the
ServiceOut
objects at the end. There I don't see how to fix that for now, unless we reduce the number of objects?Using the new async engine in SQLalchemy implies:
acquire()
withconnect()
async for row...
then one needs to callconn.stream(
instead ofconn.execute(
sa.DDL
type with the string insideAdditional:
postgres_service.py
Bonus:
reference for SQLAlchemy in async mode: https://docs.sqlalchemy.org/en/14/orm/extensions/asyncio.html#synopsis-core
Related issue/s
How to test
Checklist