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) <rkuo@onyx.app>
This commit is contained in:
rkuo-danswer 2025-03-09 20:07:30 -07:00 committed by GitHub
parent 104c4b9f4d
commit 6ca400ced9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 7 additions and 7 deletions

View File

@ -114,3 +114,4 @@ To try the Onyx Enterprise Edition:
## 💡 Contributing ## 💡 Contributing
Looking to contribute? Please check out the [Contribution Guide](CONTRIBUTING.md) for more details. Looking to contribute? Please check out the [Contribution Guide](CONTRIBUTING.md) for more details.

View File

@ -153,7 +153,8 @@ def send_email(
msg = MIMEMultipart("alternative") msg = MIMEMultipart("alternative")
msg["Subject"] = subject msg["Subject"] = subject
msg["To"] = user_email msg["To"] = user_email
msg["From"] = mail_from if mail_from:
msg["From"] = mail_from
msg["Date"] = formatdate(localtime=True) msg["Date"] = formatdate(localtime=True)
msg["Message-ID"] = make_msgid(domain="onyx.app") msg["Message-ID"] = make_msgid(domain="onyx.app")

View File

@ -1,6 +1,5 @@
from sqlalchemy import and_ from sqlalchemy import and_
from sqlalchemy import delete from sqlalchemy import delete
from sqlalchemy import func
from sqlalchemy import or_ from sqlalchemy import or_
from sqlalchemy import select from sqlalchemy import select
from sqlalchemy.orm import Session 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)) stmt = delete(Document__Tag).where(Document__Tag.document_id.in_(document_ids))
db_session.execute(stmt) db_session.execute(stmt)
orphan_tags_query = ( orphan_tags_query = select(Tag.id).where(
select(Tag.id) ~db_session.query(Document__Tag.tag_id)
.outerjoin(Document__Tag, Tag.id == Document__Tag.tag_id) .filter(Document__Tag.tag_id == Tag.id)
.group_by(Tag.id) .exists()
.having(func.count(Document__Tag.document_id) == 0)
) )
orphan_tags = db_session.execute(orphan_tags_query).scalars().all() orphan_tags = db_session.execute(orphan_tags_query).scalars().all()