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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:10:06+00:00 2026-05-14T07:10:06+00:00

I have a problem with some code and I believe it is because of

  • 0

I have a problem with some code and I believe it is because of the expense of the queryset. I am looking for a much less expensive (in terms of time) way to to this..

log.info("Getting Users")
employees = Employee.objects.filter(is_active = True)
log.info("Have Users")

if opt.supervisor:
    if opt.hierarchical:
        people = getSubs(employees, " ".join(args))
    else:
        people = employees.filter(supervisor__name__icontains = " ".join(args))
else:
    log.info("Filtering Users")
    people = employees.filter(name__icontains = " ".join(args)) | \
         employees.filter(unix_accounts__username__icontains = " ".join(args))
    log.info("Filtered Users")

log.info("Processing data")

np = []
for person in people:
    unix, p4, bugz = "No", "No", "No"
    if len(person.unix_accounts.all()): unix = "Yes"
    if len(person.perforce_accounts.all()): p4 = "Yes"
    if len(person.bugzilla_accounts.all()): bugz = "Yes"
    if person.cell_phone != "": exphone = fixphone(person.cell_phone)
    elif person.other_phone != "": exphone = fixphone(person.other_phone)
    else: exphone = ""
    np.append({ 'name':person.name,
                 'office_phone': fixphone(person.office_phone),
                 'position': person.position,
                 'location': person.location.description,
                 'email': person.email,
                 'functional_area': person.functional_area.name,
                 'department': person.department.name,
                 'supervisor': person.supervisor.name,
                 'unix': unix, 'perforce': p4, 'bugzilla':bugz,
                 'cell_phone': fixphone(exphone),
                 'fax': fixphone(person.fax),
                 'last_update': person.last_update.ctime() })

log.info("Have data")

Now this results in a log which looks like this..

19:00:55 INFO     phone       phone Getting Users
19:00:57 INFO     phone       phone Have Users
19:00:57 INFO     phone       phone Processing data
19:01:30 INFO     phone       phone Have data

As you can see it’s taking over 30 seconds to simply iterate over the data. That is way too expensive. Can someone clue me into a more efficient way to do this. I thought that if I did the first filter that would make things easier but seems to have no effect. I’m at a loss on this one.

Thanks

To be clear this is about 1500 employees — Not too many!!

  • 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-14T07:10:06+00:00Added an answer on May 14, 2026 at 7:10 am
    1. Or Q objects together instead of QuerySets.
    2. QuerySet.select_related()
    3. QuerySet.iterator()
    4. Use QuerySet.extra() to add IS NULL fields instead of the three len() calls in the loop.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an intermittent problem with some code that writes to a Windows Event
Here's my problem - I have some code like this: <mx:Canvas width=300 height=300> <mx:Button
I have run into a bit of a tricky problem in some C++ code,
I have problem in some JavaScript that I am writing where the Switch statement
I discovered to have some problem to fully understand callbacks scoping when trying to
I have problem when I try insert some data to Informix TEXT column via
I have a problem, and was hoping I could rely on some of the
I have a problem: imagine I have a plugin-based system. I need some kind
Problem: We have a web app that calls some web services asynchronously (from the
I've some CSS problem in Firefox 3. I have several image buttons on my

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.