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)
Change History (10)
comment:1 by , 19 years ago
comment:2 by , 18 years ago
Triage Stage: | Unreviewed → Design decision needed |
---|
comment:3 by , 17 years ago
Triage Stage: | Design decision needed → Someday/Maybe |
---|
comment:4 by , 14 years ago
Severity: | normal → Normal |
---|---|
Type: | defect → New feature |
This can be easily solved in class-based views.
comment:5 by , 13 years ago
Easy pickings: | unset |
---|---|
Owner: | changed from | to
Status: | new → assigned |
UI/UX: | unset |
by , 13 years ago
Attachment: | issue_1453.diff added |
---|
comment:6 by , 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 , 12 years ago
Triage Stage: | Someday/Maybe → Accepted |
---|
comment:9 by , 11 years ago
Resolution: | → worksforme |
---|---|
Status: | assigned → closed |
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.
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.