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 6334587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:41:19+00:00 2026-05-24T18:41:19+00:00

I have a very basic ‘news feed’ page that uses generic relations, with the

  • 0

I have a very basic ‘news feed’ page that uses generic relations, with the following model:

class RecentActivity(models.Model):
    event_type = models.IntegerField(choices=EVENT_TYPES)
    timestamp = models.DateTimeField()
    content_type = models.ForeignKey(ContentType)
    object_id = models.PositiveIntegerField()
    content_object = generic.GenericForeignKey('content_type', 'object_id')
    credits = models.ManyToManyField('videos.VideoCredit', blank=True) 

I am using signals to listen for when an object is created and checking to make sure it exists (i.e., it was not deleted) in the view before showing it. It is a very basic page, with only a couple dozen lines of code to generate it. However, it is generating tons of db queries! On a page of about 20 recent activity objects, it takes about 120 queries, and I estimate it’ll max out around 200 queries.

What would be the best way to get around this? My primary concern is not in reducing the number of queries, but in making the page load as fast as possible. (My first thought was denormalizing.)

Note that the page is not dynamic per-user, but will be the same for all users. Thank you.

  • 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-24T18:41:19+00:00Added an answer on May 24, 2026 at 6:41 pm

    Hard to say without more information but the usual steps I take are:

    1. Use django-debug-toolbar to find out exactly what queries are running
    2. Use select_related on the queries that are being caused by following foreign keys
    3. Use {% with %} etc. for queries that are being generated by multiple accesses within a template.

    Looking at your model, you are probably accessing content_type and then content object. If you follow credits at all you’ll easily hit that number of queries.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very basic web page that uses flot to create a canvas
I have a very basic data class that is subclassed from NSObject. I declare
I have a very basic class that is a list of sub-classes, plus some
I have a very basic model: class Link(models.Model): title = models.CharField(max_length=250, null=False) user =
I have some very basic semaphore code that works great on Linux, but cannot
I have a very basic doubt regarding the method that gets executed when app
I have very basic class: class Customer { protected $id; protected $customer; public function
I have a very basic doubt regarding cloud computing that is catching up pretty
I have a very basic regular expression that I just can't figure out why
I have a very basic application that has buttons in a toolstrip. When a

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.