Closed (duplicate)
Project:
Drupal core
Version:
8.0.x-dev
Component:
views.module
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
19 Oct 2012 at 12:29 UTC
Updated:
29 Jul 2014 at 21:22 UTC
+++ b/core/modules/comment/lib/Drupal/comment/Plugin/views/field/NodeNewComments.phpundefined
@@ -0,0 +1,124 @@
+ if ($nids) {
+ $query = db_select('node', 'n');
+ $query->addField('n', 'nid');
+ $query->innerJoin('comment', 'c', 'n.nid = c.nid');
+ $query->addExpression('COUNT(c.cid)', 'num_comments');
+ $query->leftJoin('history', 'h', 'h.nid = n.nid');
+ $query->condition('n.nid', $nids);
+ $query->where('c.changed > GREATEST(COALESCE(h.timestamp, :timestamp), :timestamp)', array(':timestamp' => NODE_NEW_LIMIT));
+ $query->condition('c.status', COMMENT_PUBLISHED);
+ $query->groupBy('n.nid');
Query isn't dynamic.
Comments
Comment #1
xjmSo this issue could be interpreted to mean "revert this to a static query" or "rewrite the WHERE condition somehow."
Comment #2
chx commented$query->where('c.changed > GREATEST(COALESCE(h.timestamp, :timestamp), :timestamp)', array(':timestamp' => NODE_NEW_LIMIT));
I think that's a PDO exception because the number of placeholders dont match the number of replacements. You can't repeat placeholders.
Comment #3
damien tournoud commentedAlso, this is a query that doesn't make any sense. I'm even surprised MySQL can extract a query plan from there.
Comment #4
xjmTurns out we have a duplicate of this with a patch at #1817672: replace db_select() with an injected database connection in views plugins.
Comment #5
damien tournoud commentedI don't think there is a way to do this query properly (we want to count the number of comments posted to a list of nodes after the time the user last seen each node), other then with an ugly correlated scalar subquery:
So I just suggest we do like the forum module does in
forum_get_topics().Comment #6
damien tournoud commented