refactor: better model serialization to minimize conversion time#246
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors admin user serialization to reduce response conversion overhead by mapping SQLModel/SQLAlchemy models directly into Pydantic response schemas via from_attributes.
Changes:
- Enable
from_attributesonBiocommonsUserResponse,PlatformMembershipData, andGroupMembershipDataso routes can return DB models directly. - Add computed properties on membership models to supply API-facing fields (
platform_name,group_name,group_short_name,updated_by_email). - Adjust admin user query construction to optionally skip membership eager-loading, and update the count query path.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| routers/admin.py | Switch admin user endpoints to return ORM users directly; add query option to skip eager-loading for count queries; cache allowed-resource subqueries. |
| db/types.py | Configure membership response models for attribute-based loading; alias updated_by from updated_by_email; enforce timezone awareness for updated_at. |
| db/models.py | Add computed properties used by attribute-based serialization for membership name fields and updater email. |
uwwint
approved these changes
Mar 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Try to map our DB models more directly to the API response schemas - minimize the amount of processing that needs to happen to convert data into a response
Changes
Checklist
How to Test Manually (if necessary)
Run
uv run pytest