Hi all, i'm having a performance issue on Drupal 6, i'm not sure if it's the views module or what.
I have a static table called internal_home wich it's filled by node_api hooks, then, i have a view that collects the info stored in this table and shows it in a page called home(with templates, blah blah)...
Now, the problem is that, in the views ui constructor, the query is this:
SELECT internal_home.nid AS nid,
internal_home.datetime AS internal_home_datetime,
internal_home.private AS internal_home_private,
internal_home.promoted AS internal_home_promoted,
internal_home.sticky AS internal_home_sticky,
internal_home.tid AS internal_home_tid,
internal_home.url_alias AS internal_home_url_alias,
internal_home.url_img_tax AS internal_home_url_img_tax,
internal_home.url_path_tax AS internal_home_url_path_tax,
internal_home.titulo AS internal_home_titulo
FROM internal_home internal_home
WHERE (internal_home.promoted = 1) AND (internal_home.sticky = 0)
)
ORDER BY internal_home_datetime DESC
But when a access to the site like a regular user, the query becomes:
SELECT DISTINCT(internal_home.nid) AS nid,
internal_home.datetime AS internal_home_datetime,
internal_home.private AS internal_home_private,
internal_home.promoted AS internal_home_promoted,
internal_home.sticky AS internal_home_sticky,
internal_home.tid AS internal_home_tid,
internal_home.url_alias AS internal_home_url_alias,
internal_home.url_img_tax AS internal_home_url_img_tax,
internal_home.url_path_tax AS internal_home_url_path_tax,
internal_home.titulo AS internal_home_titulo
FROM internal_home internal_home
INNER JOIN node_access na ON na.nid = internal_home.nid WHERE (na.grant_view >= 1 AND ((na.gid = 0 AND na.realm = 'all') OR (na.gid = 1 AND na.realm = 'private') OR (na.gid = 1 AND na.realm = 'private') OR (na.gid = 82800 AND na.realm = 'private_author') OR (na.gid = 0 AND na.realm = 'og_public'))) AND ( (internal_home.promoted = 1) AND (internal_home.sticky = 0)
)ORDER BY internal_home_datetime DESC
and now i have a big performance issue because that inner join... there's something overwriting the view's query and i cant find where it's
is there any way to bypass that call to node_access and the DISTINCT directive ? i don't mind hacking core(yeah... i know...)
a big thanks in advance
Comments
Comment #1
dawehnerThis is caused by http://api.drupal.org/api/function/node_db_rewrite_sql/6
It rewrites the output of queryies runned with db_rewrite_sql. Really be sure, you know what you are doing, the users could see nodes, which they shouldn't be able.
It would be better if you extend the views_plugin_query_default class and change the execute method and remove the call to db_rewrite_sql
Comment #2
gsvitak commentedHello,
Does anyone have any examples on how to override the views_plugin_query_default class or point me to some documentation/existing modules that implement this functionality? I want to implement my own execute method to work around the native views_pre_execute hook where I want to control the Sql that is executed. I cannot find a starting point so if someone could point me in the right direction, I would greatly appreciate it.
THanks,
G
Comment #3
dawehnerStarting point:
There you change
Thats it.
There is already another issue with the same request. It would be cool if someone could find it :)
Comment #4
gsvitak commentedthank you for the quick response. I will post my example once I am completed for others and I will look for the other issue and post the link once I find it.
Sorry I am newer to php so please forgive the following..
Do I need to implement all of the other methods of the default class similar to an interface in java or c# or can I only override the execute functionality?
G
Comment #5
dawehnerYou can use
Then you don't have to write all methods. Just like every other polymorphismn.
Comment #6
gsvitak commentedHello
Thank you for the help.
I have not located a similar example so please forgive my ignorance and I have not found any documentation on the hook views_data_alter. Most other examples that implement the views_data_alter hook implement handlers for relationships or filters. I am not trying to use either of these concepts and was hoping you could provide some more guidance.
I understand the extending piece of the class thank you. However, I am trying to filter the nodes in the view to include matching nodes based on the user driveeen preference set in the the user profile.
So for my hook definition I assume I would use the following in the modulename_views.inc:
$data['node']['table']['base']['query class'] = 'yourqueryclass';and then include the query class in the modulename_views.inc.
Could you please verify my thoughts and add any suggestions?
Thanks
G
Comment #7
enboig commentedI am really interested in this; I need to list inside a node a list of other nodes which shouldn't be visible for the user. Is there a way to "dissable" db_rewrite_sql() and just call db_query() for a view?
Comment #8
dawehnerenboig: That's really the same question as the issue poster. There is a patch for 3.x which allows this.
But sadly by design this is only for 3.x
Comment #9
iamjon commentedThis issue has been addressed in views 3.x.