⚡ Bolt: Optimize email list processing in API and Repository #38
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.
This PR implements micro-optimizations in the email list retrieval path.
Changes:
Repository Layer (
backend/infrastructure/db/repositories.py):get_previews_by_folderto use a list comprehension for creatingEmailentities. This is generally faster and more pythonic than initializing an empty list and calling.append()in a loop.API Layer (
backend/api/mail.py):preview_body = full_body[:100]slicing operation inEmailListResponse.from_entity. TheEmailRepositoryalready usesfunc.substr(..., 1, 100)in the SQL query, so theentity.bodyis already truncated.getattr(entity, 'field', None)with direct attribute accessentity.fieldforsender_display_nameandsender_email. SinceEmailis a strictly defined Dataclass (verified inbackend/core/entities/email.py), these fields are guaranteed to exist, makinggetattroverhead unnecessary.Verification:
backend/infrastructure/db/repositories.pycontainsfunc.substr(EmailModel.body, 1, 100).backend/core/entities/email.pydefinessender_display_nameandsender_emailas fields in theEmaildataclass.PR created automatically by Jules for task 15779769181692970060 started by @Mr-Dark-debug