Fix duplicate detection for tasks generated by change tasks-factory

When both the `--task--applicable` and `--task--invalid` attribute
flags are passed to a gerrit query, the task plugin currently fails to
detect duplicate tasks generated by change type tasks-factory. This
happens because the `nodeSetByBaseTasksFactory` map is not populated.

As a result, if the change tasks-factory produces duplicate tasks, such
as in the case when the query used for generating the tasks results in
cyclic dependencies, the plugin attempts to create nodes for each task.
This leads to excessive memory usage, degraded query performance, and
in extreme cases, server instability.

This change fixes the issue by ensuring the `nodeSetByBaseTasksFactory`
map is correctly populated.

Change-Id: If747f9ff1f4ee807f9630de2974b159cee4a762f
diff --git a/src/main/java/com/googlesource/gerrit/plugins/task/TaskPluginDefinedInfoFactory.java b/src/main/java/com/googlesource/gerrit/plugins/task/TaskPluginDefinedInfoFactory.java
index 0791bda..700b3e2 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/task/TaskPluginDefinedInfoFactory.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/task/TaskPluginDefinedInfoFactory.java
@@ -243,6 +243,10 @@
               attribute.path = MISSING_VIEW_PATH_CAPABILITY;
             }
           }
+          if (node.isChange()) {
+            node.getNodeSetByBaseTasksFactory().get(task.subSection).add(node.key());
+          }
+
           boolean groupApplicable = attribute.status != null;
 
           if (groupApplicable || !options.onlyApplicable) {
@@ -264,9 +268,6 @@
                 attribute.evaluationMilliSeconds = millis() - attribute.evaluationMilliSeconds;
               }
               addStatistics(attribute.statistics);
-              if (node.isChange()) {
-                node.getNodeSetByBaseTasksFactory().get(task.subSection).add(node.key());
-              }
               return Optional.of(attribute);
             }
           }