marshmallow-code / marshmallow-sqlalchemy

SQLAlchemy integration with marshmallow
https://marshmallow-sqlalchemy.readthedocs.io
MIT License
549 stars 94 forks source link

Use Session.get() in `get_instance` instead of Session.query() #548

Closed zippolyte closed 6 months ago

zippolyte commented 6 months ago

Session.get() (SQLA docs) tries to fetch an object from the session's identity map if it exists, and performs a SQL query otherwise.

This improves load() performance by reducing number of SQL queries, especially for nested relationships, if everything is already available into the session.

sloria commented 6 months ago

TIL about Session.get. Thanks for this PR!