+++ 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

xjm’s picture

Project: VDC » Drupal core
Version: » 8.x-dev
Component: Code » views.module

So this issue could be interpreted to mean "revert this to a static query" or "rewrite the WHERE condition somehow."

chx’s picture

$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.

damien tournoud’s picture

Also, this is a query that doesn't make any sense. I'm even surprised MySQL can extract a query plan from there.

xjm’s picture

Status: Active » Closed (duplicate)
damien tournoud’s picture

Status: Closed (duplicate) » Active

I 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:

SELECT nid, (SELECT COUNT(*) FROM comment c WHERE c.changed > GREATEST(COALESCE(h.timestamp, :timestamp), :timestamp)) count FROM node n LEFT JOIN history h ON h.nid = n.nid AND h.uid = :uid

So I just suggest we do like the forum module does in forum_get_topics().

damien tournoud’s picture

Status: Active » Closed (duplicate)