rhtyd commented on a change in pull request #4140: URL: https://github.com/apache/cloudstack/pull/4140#discussion_r439908149
########## File path: server/src/main/java/com/cloud/api/query/QueryManagerImpl.java ########## @@ -3423,12 +3432,32 @@ else if (!template.isPublicTemplate() && caller.getType() != Account.ACCOUNT_TYP return uniqueTmplPair; } List<TemplateJoinVO> uniqueTmpls = uniqueTmplPair.first(); - String[] tzIds = new String[uniqueTmpls.size()]; int i = 0; - for (TemplateJoinVO v : uniqueTmpls) { - tzIds[i++] = v.getTempZonePair(); + List<TemplateJoinVO> vrs = null; + if (showUnique) { + Long[] tzIds = new Long[uniqueTmpls.size()]; + for (TemplateJoinVO v : uniqueTmpls) { + tzIds[i++] = v.getId(); + } + vrs = _templateJoinDao.findByIds(tzIds); + + // Get only unique id rows + Long lastId = null; + for(i = vrs.size() - 1; i >= 0; i--) { + if (new Long(vrs.get(i).getId()).equals(lastId)) { + vrs.remove(i); Review comment: Please explore if you can simplify the code ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org