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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:12:34+00:00 2026-05-22T12:12:34+00:00

I’ve been wrestling with this problem for at least two days. There’s a view

  • 0

I’ve been wrestling with this problem for at least two days.
There’s a view that produces a page showing all phone calls that a certain user/phone extension made. Nothing fancy, just a long page, maximum of 1000 lines.

This view function receives some parameters from the url in order to choose what to show on this page. There are two situations, one where an "extension=xxxxxx" is passed and one where "user=xxxx" is passed in the url:

if request.GET.get("extension", None):
    # extension_query expects only one Extension object
    extension_query = Extension.objects.filter(number=request.GET["extension"])
    ... # Here I do some conditionals to match the right Extension object.
elif request.GET.get("user", None):
    ... # Simple stuff, nothing to significant.
# at the end I call render_to_response normally

Edit – this is the piece of code that calls my customized render_to_response:
Edit2 – after John C’s suggestion of forcing the evaluation of the queryset, the load time decreased from 1.6 min to 14s: Now I cast my calls to a list() before passing it to my customized render_to_response:

if (request.GET.get("format", None) == "screen"
    or request.GET.get("print", False)):
    ctx = dict(calls=list(calls), client=client, extension=extension,
               no_owner_extension=no_owner_extension,
               start=start_date, end=end_date, tab="clients",
               owner=user)
    return finish_request(
        request, "reports/exporting_by_call_type.html", ctx)

This is my customized render_to_response:

def finish_request(request, template, context):
    if "print" in request.GET or "print" in request.POST:
        context.update(printing=True)
    return render_to_response(
        template, RequestContext(request, context))

In my development machine, it takes 3-4 seconds to fully process this view for a realistic data scenario according to the Chrome audit for BOTH situations. In production it takes 3-4 seconds to load the view where user parameter is passed in the URL, but when extension is passed, it takes 2 minutes!

Edit: It’s important to say that the difference between passing user or extension in the URL doesn’t change the final rendered page except one line at the top where I indicate since when the extension number belongs to someone. The rest of the data is exactly the same.

I profiled every little block in my code involved in generating this view. I timed how long the view takes to render_to_response in my production code (0.05 seconds). I took out parts where extension is called in my template but with no success. I also used django_debug_toolbar to see what every SQL statement is doing and at most, the queries take 2 seconds.

I should also add that I’m using mod_wsgi, debug=False on my production settings…
YSlow rates this page a 94 despite taking 2 minutes.

Can anyone shed some light?

  • 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-22T12:12:35+00:00Added an answer on May 22, 2026 at 12:12 pm

    I don’t see anything obviously wrong with that code. One question I have, is are you expecting exactly one object to match? If so, might be worth trying this code:

    getData = request.GET.copy() # optional, I like my own copy.
    if 'extension' in getData:
        ext = getData['extension']
        extObj = Extension.objects.get(number__exact=ext) # double-underline
    # elif...
    

    Note that will result in an Extension object, not a Queryset. If you have multiple extensions, then you do need to use filter – but I’d still suggest using exact, as well as moving the reading of ext from the dictionary, to outside of the filter statement.

    Update (from my comments) – try forcing the Queryset to be evaluated immediately using a call to list(), see if that has an effect on render_to_response.

    Update 2 – since it did have an effect – here’s what I think might be happening. Since Django Querysets use lazy evaluation, when the template finally executes – it’s calling an iterator, not an existing list. Maybe there’s just too many function calls going on, and each call to the iterator to get a new value, is incurring a lot of unnecessary overhead. Or maybe there’s a bug. 🙂

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I am doing a simple coin flipping experiment for class that involves flipping 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.