Skip to content

fix(email-service): Upsert thread history when upserting draft#958

Merged
evanhutnik merged 2 commits intomainfrom
evan/fix-drafts-preview
Jan 13, 2026
Merged

fix(email-service): Upsert thread history when upserting draft#958
evanhutnik merged 2 commits intomainfrom
evan/fix-drafts-preview

Conversation

@evanhutnik
Copy link
Copy Markdown
Contributor

@evanhutnik evanhutnik commented Jan 13, 2026

Summary

Title

Screenshots, GIFs, and Videos

@claude
Copy link
Copy Markdown
Contributor

claude bot commented Jan 13, 2026

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

#[tracing::instrument(skip(pool), level = "info")]
pub async fn upsert_user_history(
pool: &PgPool,
#[tracing::instrument(skip(executor), level = "info")]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

remove level = "info". I'd also recommend adding err here to automatically log the specific error

.execute(pool)
.execute(executor)
.await
.map_err(|_| anyhow!("Failed to upsert user history"))?;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

instead of mapping to anyhow error that loses all the context of the actual error you can just do .await?

combined with my recommendation above this could help with giving us better logs to see what actually errors

.context("unable to fetch from email id")?;

insert_message_to_send(tx, draft, thread_db_id.unwrap(), from_email_id, true)
insert_message_to_send(tx, draft, thread_db_id, from_email_id, true)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Instead of creating this thread_db_id couldn't you just use draft.thread_db_id since it's explicitly set in the else if it's not already present.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

don't know which approach is cleaner, just giving alternative

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

draft.thread_db_id is optional so that would require us to call unwrap on it, which isn't great imo - i think this is the cleaner way

@evanhutnik evanhutnik merged commit deee52b into main Jan 13, 2026
39 checks passed
@evanhutnik evanhutnik deleted the evan/fix-drafts-preview branch January 13, 2026 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants