Opened 19 years ago

Closed 11 years ago

#1453 closed New feature (worksforme)

generic views sometimes inefficient with large data sets - especially archive_index

Reported by: hugo Owned by: zefciu
Component: Generic views Version:
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

archive_index will give a list of years with available data to the template in the context. To discover these years, it will do the following SQL:

SELECT DATE_TRUNC(\'year\', "logviewer_message"."time")
FROM "logviewer_message"
WHERE ("logviewer_message"."channel_id" = 2 AND 
       "logviewer_message"."time" <= 2006-03-02 12:07:20.758531)
GROUP BY 1 ORDER BY 1 ASC

This is rather icky if you have very much data in your database. For example the IRC logger currently has over 100000 messages stored for the #django channel. It will do an index scan for the timestamp - but that is allways "now" in archive_index, so it won't help much. It will essentially dig through all rows sequentially.

I think either this list of years should be thrown out or should be made optional (add a with_list_of_years parameter to the generic view that people can set if they need this behaviour).

Attachments (1)

issue_1453.diff (8.5 KB ) - added by zefciu 13 years ago.

Download all attachments as: .zip

Change History (10)

comment:1 by Esaj, 19 years ago

How about putting an object in the context which can lazily get a list of years or months? I think it's more KISS than adding another parameter :) Getting a list of months in archive_index would actually be quite useful, in particular for blogs.

comment:2 by Simon G. <dev@…>, 18 years ago

Triage Stage: UnreviewedDesign decision needed

comment:3 by Jacob, 17 years ago

Triage Stage: Design decision neededSomeday/Maybe

comment:4 by Łukasz Rekucki, 14 years ago

Severity: normalNormal
Type: defectNew feature

This can be easily solved in class-based views.

comment:5 by zefciu, 13 years ago

Easy pickings: unset
Owner: changed from nobody to zefciu
Status: newassigned
UI/UX: unset

by zefciu, 13 years ago

Attachment: issue_1453.diff added

comment:6 by zefciu, 13 years ago

Has patch: set

I have created a patch that makes date_list in both class-based and function-based views lazy. Also created some tests to check the behavior of function-based archive-index (there were none before) and to ensure date_list is a Promise

comment:7 by Aymeric Augustin, 12 years ago

Triage Stage: Someday/MaybeAccepted

comment:8 by Tim Graham, 11 years ago

Patch needs improvement: set

Patch doesn't apply cleanly to master.

comment:9 by Marc Tamlyn, 11 years ago

Resolution: worksforme
Status: assignedclosed

My instinct is that if you have the problem then you should override your view and make get_date_list return None, or however you wish to handle it. Wrapping the date_list in lazy objects adds some complexity, and saves errors in the defaults, but only if you don't actually use date_list in your template. If you do use date_list then you have the same performance problem. It is easy enough to avoid the performance issue by overriding a single method in the CBV.

Note: See TracTickets for help on using tickets.
Back to Top