Skip to content

fix(imap): deduplicate scan results on insertion#234

Merged
Userunknown84 merged 1 commit into
Userunknown84:mainfrom
devprashant19:fix/imap-scan-deduplication
Jun 24, 2026
Merged

fix(imap): deduplicate scan results on insertion#234
Userunknown84 merged 1 commit into
Userunknown84:mainfrom
devprashant19:fix/imap-scan-deduplication

Conversation

@devprashant19

Copy link
Copy Markdown
Contributor

Description

This PR fixes a bug in backend/email_connectors/imap_store.py where IMAP scan results were inserted blindly on every scan cycle. Because there was no deduplication, the same emails were re-inserted every time the inbox was scanned, causing the database table to grow indefinitely (~144,000 redundant rows per month per user on a 15-minute interval).
Closes #223

Changes

  • Updated save_scan_results() in imap_store.py to first query the database for existing message_ids.
  • Filtered the incoming scanned_emails list to only execute INSERT statements for emails that are not already present in the database.
  • This approach safely prevents duplicates without requiring complex schema migrations on the deployed SQLite database.

Related Issues

  • Resolves the unbounded IMAP scan results duplication bug.

Type of Change

  • Security fix
  • Bug fix
  • New feature
  • Performance improvement

Pre-submission Checklist

  • Verified that repeated scans do not result in duplicate records in imap_scan_results.
  • Ensured new emails are still successfully inserted.

@vercel

vercel Bot commented Jun 23, 2026

Copy link
Copy Markdown

@devprashant19 is attempting to deploy a commit to the Aditya Sharma's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎉 Thank you for your first Pull Request!

We appreciate your contribution to the project.

Please ensure:

  • Your code follows the project guidelines.
  • All tests pass successfully.
  • A clear description of the changes is provided.

A maintainer will review your PR shortly. 🚀

@Userunknown84 Userunknown84 merged commit 06e33c2 into Userunknown84:main Jun 24, 2026
3 of 4 checks passed
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.

Bug: IMAP Scan Results Never Deduplicated — Same Emails Re-Inserted Every Scan, Table Grows ~144,000 Rows/Month Per User

2 participants