Use values_list queryset to lower amount of queries

RESOLVED FIXED

Status

developer.mozilla.org
Code Cleanup
RESOLVED FIXED
3 years ago
3 years ago

People

(Reporter: jezdez, Assigned: jezdez)

Tracking

Details

(Whiteboard: [specification][type:bug])

(Assignee)

Description

3 years ago
What did you do?
================
I found lots of code like this:

  spams = [foo.spam for foo in Egg.objects.all()]

This can be written like which reduces Python load:

  spams = Egg.objects.values_list('spam', flat=True)


What happened?
==============
I guffawed.

What should have happened?
==========================
I should sing tralalalalaalala

Is there anything else we should know?
======================================
(Assignee)

Updated

3 years ago
Component: General → Code Cleanup
(Assignee)

Updated

3 years ago
Assignee: nobody → jezdez
Status: NEW → ASSIGNED

Comment 1

3 years ago
Commits pushed to master at https://github.com/mozilla/kuma

https://github.com/mozilla/kuma/commit/105ca04c03e92d28204fdd1c0025b3a6413bb8d2
Bug 1148896 - Add own superuser_required decorator.

https://github.com/mozilla/kuma/commit/946d25bb17da8bffe7963453756c4c61a3b104b9
Fix bug 1148896 - Stop using bad db query patterns.

That includes getting a list of single column values from the database
as well as some other issues.

https://github.com/mozilla/kuma/commit/8fabccd62739c0a7fb272a465070caeab7f8cfee
Bug 1148896 - Use more Django shortcuts.

https://github.com/mozilla/kuma/commit/1a30144594442cc4291a070f62de8780d9d7016c
Bug 1148896 - Apply more code best practices.

https://github.com/mozilla/kuma/commit/f8b9f86de4206b84eadc007d219fdc08adb72220
Merge pull request #3148 from mozilla/bug1148896

Code cleanups and best practices applied.

Updated

3 years ago
Status: ASSIGNED → RESOLVED
Last Resolved: 3 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.