Avatar ·

Working with a large number of records in the session

📁 function, Flask microframework, AI, work, project

What is the correct way to work with a large number of records with SQLAlchemy?

I have two tables. The first 5 million records have the following types: question_id, view_count, counted. The second table contains the sum of view_count for each unique question_id. If we took into account the entry from the first table in the second, counted is set to true.

Right now it looks like this:

def update_most_viewed(): 
    query = QuestionViewHistory.query.filter_by(counted=False).distinct()    
    question_count = query.count()    
    frame_size =