From 6ca400ced9525b2715af28c154bbbfab2fedc12c Mon Sep 17 00:00:00 2001 From: rkuo-danswer Date: Sun, 9 Mar 2025 20:07:30 -0700 Subject: [PATCH] Bugfix/delete document tags slow (#4232) * Add Missing Date and Message-ID Headers to Ensure Email Delivery * fix issue Performance issue during connector deletion #4191 * fix ruff * bump to rebuild PR --------- Co-authored-by: ThomaciousD <2194608+ThomaciousD@users.noreply.github.com> Co-authored-by: Richard Kuo (Danswer) --- README.md | 1 + backend/onyx/auth/email_utils.py | 3 ++- backend/onyx/db/tag.py | 10 ++++------ 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 442f8404f..3066a2982 100644 --- a/README.md +++ b/README.md @@ -114,3 +114,4 @@ To try the Onyx Enterprise Edition: ## 💡 Contributing Looking to contribute? Please check out the [Contribution Guide](CONTRIBUTING.md) for more details. + diff --git a/backend/onyx/auth/email_utils.py b/backend/onyx/auth/email_utils.py index 6f677b12e..15d3fc8ec 100644 --- a/backend/onyx/auth/email_utils.py +++ b/backend/onyx/auth/email_utils.py @@ -153,7 +153,8 @@ def send_email( msg = MIMEMultipart("alternative") msg["Subject"] = subject msg["To"] = user_email - msg["From"] = mail_from + if mail_from: + msg["From"] = mail_from msg["Date"] = formatdate(localtime=True) msg["Message-ID"] = make_msgid(domain="onyx.app") diff --git a/backend/onyx/db/tag.py b/backend/onyx/db/tag.py index 1d5b553f8..0c6ebb42d 100644 --- a/backend/onyx/db/tag.py +++ b/backend/onyx/db/tag.py @@ -1,6 +1,5 @@ from sqlalchemy import and_ from sqlalchemy import delete -from sqlalchemy import func from sqlalchemy import or_ from sqlalchemy import select from sqlalchemy.orm import Session @@ -149,11 +148,10 @@ def delete_document_tags_for_documents__no_commit( stmt = delete(Document__Tag).where(Document__Tag.document_id.in_(document_ids)) db_session.execute(stmt) - orphan_tags_query = ( - select(Tag.id) - .outerjoin(Document__Tag, Tag.id == Document__Tag.tag_id) - .group_by(Tag.id) - .having(func.count(Document__Tag.document_id) == 0) + orphan_tags_query = select(Tag.id).where( + ~db_session.query(Document__Tag.tag_id) + .filter(Document__Tag.tag_id == Tag.id) + .exists() ) orphan_tags = db_session.execute(orphan_tags_query).scalars().all()