Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6967961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:23:22+00:00 2026-05-27T16:23:22+00:00

I have two models – ChatCurrent – (which stores the messages for the current

  • 0

I have two models –

ChatCurrent – (which stores the messages for the current active chats)
ChatArchive – (which archives the messages for the chats that have ended)

The reason I’m doing this is so that the ChatCurrent table always has minimum number of entries, making querying the table fast (I don’t know if this works, please let me know if I’ve got this wrong)

So I basically want to copy (cut) data from the ChatCurrent to the ChatArchive model. What would be the fastest way to do this. From what I’ve read online, it seems that I might have to execute a raw SQL query, if you would be kind enough to even state the Query I’ll be grateful.

Additional details –
Both the models have the same schema.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T16:23:23+00:00Added an answer on May 27, 2026 at 4:23 pm

    My opinion is that today they are not reason to denormalize database in this way to improve performance. Indexes or partitioning + indexes should be enought.

    Also, in case that, for semantic reasons, you prefer have two tables (models) like: Chat and ChatHistory (or ChatCurrent and ChatActive) as you say and manage it with django, I thing that the right way to keep consistence is to create ToArchive() method in ChatCurrent. This method will move chat entries to historical chat model. You can perform this operation in background mode, then you can thread the swap in a celery process, in this way online users avoid wait for request. Into celery process the fastest method to copy data is a raw sql. Remember that you can encapsulate sql into a stored procedure.

    Edited to include reply to your comment

    You can perform ChatCurrent.ToArchive() in ChatCurrent.save() method:

    class ChatCurrent(model.Model):
        closed=models.BooleanField()
    
        def save(self, *args, **kwargs):
            super(Model, self).save(*args, **kwargs)
            if self.closed:
                self.ToArchive()
    
        def ToArchive(self):
            from django.db import connection, transaction
            cursor = connection.cursor()            
            cursor.execute("insert into blah blah")
            transaction.commit_unless_managed()
            #self.delete()  #if needed (perhaps deleted on raw sql)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two models, Article and Post that both inherit from a base model
I have two models, Room and Image . Image is a generic model that
I have two models: Person and Relation. The second one stores information about relations
I have two models that has a manytomany relationship with a 'through' table in
I have two models, TreeNode and User. Each user has_one TreeNode, which is the
I have two models in a has_many relationship such that Log has_many Items. Rails
I have two models that are related to each other. For a contrived example,
I have two models. Deals and Stores. I want to add already created Deals
I have two models: One which contains :city_name, :long, :lat and the other :person_name,
I have two Models, Events and Users that share a many to many association.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.