This is an automated email from the ASF dual-hosted git repository.

Pearl1594 pushed a commit to branch improve-listtemplates-perf
in repository https://gitbox.apache.org/repos/asf/cloudstack.git

commit 54d43925a466d4da0c7f1ce7bd16a9e03b5573c0
Author: mprokopchuk <[email protected]>
AuthorDate: Mon Jul 6 16:32:06 2026 -0700

    Improve BypassTemplateView config description and rename helper method
---
 .../main/java/org/apache/cloudstack/query/QueryService.java   | 11 ++++++-----
 .../java/com/cloud/api/query/dao/TemplateJoinDaoImpl.java     |  8 ++++----
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/api/src/main/java/org/apache/cloudstack/query/QueryService.java 
b/api/src/main/java/org/apache/cloudstack/query/QueryService.java
index c950d20850b..b5820ff576b 100644
--- a/api/src/main/java/org/apache/cloudstack/query/QueryService.java
+++ b/api/src/main/java/org/apache/cloudstack/query/QueryService.java
@@ -140,11 +140,12 @@ public interface QueryService {
     ConfigKey<Boolean> ReturnVmStatsOnVmList = new ConfigKey<>("Advanced", 
Boolean.class, "list.vm.default.details.stats", "true",
             "Determines whether VM stats should be returned when details are 
not explicitly specified in listVirtualMachines API request. When false, 
details default to [group, nics, secgrp, tmpl, servoff, diskoff, backoff, iso, 
volume, min, affgrp]. When true, all details are returned including 'stats'.", 
true, ConfigKey.Scope.Global);
 
-    ConfigKey<Boolean> BypassTemplateView = new ConfigKey<>("Advanced", 
Boolean.class, "template.list.bypass.view", "false",
-            "If true, listTemplates Phase 1 (DISTINCT temp_zone_pair) bypasses 
template_view and runs a hand-tuned SQL " +
-                    "against the underlying tables. Falls back to the view 
automatically when the request uses tags, " +
-                    "sharedAccountIds, domainPath, or 
featured/community-domain filters. Toggleable at runtime; flip back " +
-                    "to false to revert without a deploy if a parity bug 
surfaces.", true, ConfigKey.Scope.Global);
+    ConfigKey<Boolean> BypassTemplateView = new ConfigKey<>("Advanced", 
Boolean.class, "template.list.bypass.view",
+            "false",
+            "If true, uses an optimized query path for listing templates and 
ISOs, which can improve performance on " +
+                    "deployments with large numbers of templates. 
Automatically falls back to the standard query when" +
+                    " filtering by tags, using the shared, featured, or 
community template filters, or when including" +
+                    " removed templates.", true, ConfigKey.Scope.Global);
 
     ListResponse<UserResponse> searchForUsers(ResponseObject.ResponseView 
responseView, ListUsersCmd cmd) throws PermissionDeniedException;
 
diff --git 
a/server/src/main/java/com/cloud/api/query/dao/TemplateJoinDaoImpl.java 
b/server/src/main/java/com/cloud/api/query/dao/TemplateJoinDaoImpl.java
index feb071a8beb..e6017649944 100644
--- a/server/src/main/java/com/cloud/api/query/dao/TemplateJoinDaoImpl.java
+++ b/server/src/main/java/com/cloud/api/query/dao/TemplateJoinDaoImpl.java
@@ -646,7 +646,7 @@ public class TemplateJoinDaoImpl extends 
GenericDaoBaseWithTagInformation<Templa
         }
 
         for (String idPair : idPairs) {
-            SearchCriteria<TemplateJoinVO> sc = 
applyPairWhereClauseHackyWorkaround(idPair);
+            SearchCriteria<TemplateJoinVO> sc = 
buildTemplateZonePairSearchCriteria(idPair);
             List<TemplateJoinVO> rows = searchIncludingRemoved(sc, 
searchFilter, null, false);
             if (rows != null) {
                 uvList.addAll(rows);
@@ -655,7 +655,7 @@ public class TemplateJoinDaoImpl extends 
GenericDaoBaseWithTagInformation<Templa
         return uvList;
     }
 
-    private SearchCriteria<TemplateJoinVO> 
applyPairWhereClauseHackyWorkaround(String idPair) {
+    private SearchCriteria<TemplateJoinVO> 
buildTemplateZonePairSearchCriteria(String idPair) {
         if (idPair == null || idPair.isEmpty()) {
             throw new IllegalArgumentException("template zone pair id is null 
or empty");
         }
@@ -821,8 +821,8 @@ public class TemplateJoinDaoImpl extends 
GenericDaoBaseWithTagInformation<Templa
 
         if (filter.format != null) {
             // searchForTemplatesInternal: format = 'ISO' for isos, format != 
'ISO' otherwise.
-            where.append(filter.isIso ? " AND vt.format = ?" : " AND vt.format 
!= ?");
-            params.add(filter.format.toString());
+            String condition = filter.isIso ? "=" : "!=";
+            where.append(" AND vt.format " + condition + " 'ISO'");
         }
 
         if (filter.hypervisorType != null) {

Reply via email to