Skip to content

fix: remove orphaned chats and associated user stats in clean_chat_job - #6495

Merged
wxg0103 merged 1 commit into
v2from
pr@v2@fix_remove_chats
Jul 23, 2026
Merged

fix: remove orphaned chats and associated user stats in clean_chat_job#6495
wxg0103 merged 1 commit into
v2from
pr@v2@fix_remove_chats

Conversation

@shaohuzhang1

Copy link
Copy Markdown
Contributor

fix: remove orphaned chats and associated user stats in clean_chat_job

Copilot AI review requested due to automatic review settings July 23, 2026 04:06
@shaohuzhang1

Copy link
Copy Markdown
Contributor Author

Seems you are using me but didn't get OPENAI_API_KEY seted in Variables/Secrets for this repo. you could follow readme for more information

Copilot AI 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.

Pull request overview

Fixes cleanup behavior in clean_chat_job so that when orphaned Chat rows (no ChatRecord) are removed, related per-user access stats can also be cleaned up.

Changes:

  • Import ApplicationChatUserStats into the chat cleanup job.
  • Extend the orphaned-chat deletion logic to also delete related ApplicationChatUserStats entries.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +91 to +100
chats = Chat.objects.filter(
chatrecord__isnull=True,
id__in=chat_ids,
)

user_ids = list(chats.values_list("user_id", flat=True).distinct())

ApplicationChatUserStats.objects.filter(chat_user_id__in=user_ids).delete()

chats.delete()
@wxg0103
wxg0103 merged commit cb7ebbd into v2 Jul 23, 2026
5 of 7 checks passed
@wxg0103
wxg0103 deleted the pr@v2@fix_remove_chats branch July 23, 2026 04:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants