Closed (fixed)
Project:
Views (for Drupal 7)
Version:
6.x-2.x-dev
Component:
Miscellaneous
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
4 Nov 2009 at 19:12 UTC
Updated:
6 Nov 2010 at 08:15 UTC
Jump to comment: Most recent file
Comments
Comment #1
dawehnerThis introduces a new query for every non-pager view.
Perhaps there should be a setting.
Comment #2
marcp commentedIt should only introduce the new query when the $view->get_total_rows flag is set. It's already querying when there's a pager involved. http://drupal.org/node/347819#comment-2071008 makes me believe that this was working at one point.
Normal non-pager views shouldn't have $view->get_total_rows set -- see that link above for the trick to get it to work.
Comment #3
dawehnerAh ok. Thanks for it. Wouldn't it be cool, if this kind of documentation whould be somehow in views? For example make a patch to advanced help, or do some inline comments.
The patch is fine.
Comment #4
merlinofchaos commentedBefore I commit this i Just want to be sure: The only situation where this is actually broken is where items_per_page is set to 0, right? So you're always getting all results and want to know how many results were loaded?
Note that count($view->result) will provide this value in that case, without running an extra query. I'm not completely sure that we want to run an extra query to get data you already have.
Comment #5
marcp commentedYep, that's right. I tested
count($view->result)and it works perfectly, so we definitely should not run another count query.If the format of $view->result ever changes, then any code that depends upon
count($view->result)being the number of rows will be broken.It seems more likely that
total_rowswould remain a fixture in the view, so maybe the fix is just to settotal_rowstocount($view->result)whenitems_per_pageis set to 0 andget_total_rowsis set TRUE. That's what this new patch does.Really nothing needs to be done -- there are just multiple ways to get the "total rows" depending on the pager settings. The Views API would be cleaner with a single way to get the number of rows.
Another option would be to ditch the check on
get_total_rowsand just settotal_rowsall the time since there's no need to run an extra query. I didn't look into the implications of havingtotal_rowsset. There's something going into the views cache, buttotal_rowsis not used much in the views codebase.Comment #6
marcp commentedJust changing the title.
Comment #7
marcp commentedOne benefit to always setting
$view->total_rowsis that there would be no need to implementhook_views_pre_execute()just to set$view->get_total_rows = TRUE;.Comment #8
merlinofchaos commentedOk, I think this is right.
One minor nit: The comment should specify that we're only setting this when all items were requested; right now it suggests that all non-paged-queries will be counted like that, which isn't accurate.
Comment #9
marcp commentedNot sure if this is any better, but here's a shot at some better wording in the comment.
Comment #10
merlinofchaos commentedChanged slightly (there's no need to check to see if get_total_rows is set, since that is only there to avoid a query that isn't run in this case) and committed to all branches.