Skip to content

refactor: better model serialization to minimize conversion time#246

Merged
marius-mather merged 3 commits into
mainfrom
refactor/model-serialization
Mar 31, 2026
Merged

refactor: better model serialization to minimize conversion time#246
marius-mather merged 3 commits into
mainfrom
refactor/model-serialization

Conversation

@marius-mather

@marius-mather marius-mather commented Mar 31, 2026

Copy link
Copy Markdown
Collaborator

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

  • Map attributes of DB models to response schema fields - so we can return users directly from the database in API responses
  • Some more tweaks to user queries

Checklist

  • I have commented my code, particularly in hard-to-understand areas
  • I have added unit / integration tests that prove my fix is effective or that my feature works
  • I have run all tests locally and they pass
  • I have updated the documentation (if applicable)
  • For any new secrets, I have updated the shared spreadsheet and the GitHub Secrets.

How to Test Manually (if necessary)

Run uv run pytest

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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_attributes on BiocommonsUserResponse, PlatformMembershipData, and GroupMembershipData so 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.

Comment thread routers/admin.py
Comment thread routers/admin.py
@marius-mather marius-mather merged commit a2e7fb5 into main Mar 31, 2026
5 checks passed
@marius-mather marius-mather deleted the refactor/model-serialization branch March 31, 2026 23:00
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.

3 participants