You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ro...@apache.org on 2019/07/03 06:12:03 UTC

[cloudstack] branch master updated: server: reduce execution time while listing project if projects have many resource tags (#3306)

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

rohit pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/master by this push:
     new 452b48e  server: reduce execution time while listing project if projects have many resource tags (#3306)
452b48e is described below

commit 452b48ea0c59b99830701612d25def4ef020d63f
Author: Wei Zhou <us...@gmail.com>
AuthorDate: Wed Jul 3 08:11:53 2019 +0200

    server: reduce execution time while listing project if projects have many resource tags (#3306)
    
    If projects have many resource tags, it will take a long time to list projects.
    Remove resource tags information from project_view will fix it the issue.
    
    Fixes #3178
---
 .../resources/META-INF/db/schema-41200to41300.sql  | 32 +++++++++-
 server/src/main/java/com/cloud/api/ApiDBUtils.java |  4 --
 .../com/cloud/api/query/ViewResponseHelper.java    |  5 +-
 .../com/cloud/api/query/dao/ProjectJoinDao.java    |  2 -
 .../cloud/api/query/dao/ProjectJoinDaoImpl.java    | 23 ++-----
 .../java/com/cloud/api/query/vo/ProjectJoinVO.java | 72 ----------------------
 6 files changed, 36 insertions(+), 102 deletions(-)

diff --git a/engine/schema/src/main/resources/META-INF/db/schema-41200to41300.sql b/engine/schema/src/main/resources/META-INF/db/schema-41200to41300.sql
index 67b5f30..5ffba48 100644
--- a/engine/schema/src/main/resources/META-INF/db/schema-41200to41300.sql
+++ b/engine/schema/src/main/resources/META-INF/db/schema-41200to41300.sql
@@ -73,4 +73,34 @@ CREATE VIEW `cloud`.`data_center_view` AS
             left join
         `cloud`.`dedicated_resources` ON data_center.id = dedicated_resources.data_center_id
             left join
-        `cloud`.`affinity_group` ON dedicated_resources.affinity_group_id = affinity_group.id;
\ No newline at end of file
+        `cloud`.`affinity_group` ON dedicated_resources.affinity_group_id = affinity_group.id;
+
+-- Remove key/value tags from project_view
+DROP VIEW IF EXISTS `cloud`.`project_view`;
+CREATE VIEW `cloud`.`project_view` AS
+    select
+        projects.id,
+        projects.uuid,
+        projects.name,
+        projects.display_text,
+        projects.state,
+        projects.removed,
+        projects.created,
+        projects.project_account_id,
+        account.account_name owner,
+        pacct.account_id,
+        domain.id domain_id,
+        domain.uuid domain_uuid,
+        domain.name domain_name,
+        domain.path domain_path
+    from
+        `cloud`.`projects`
+            inner join
+        `cloud`.`domain` ON projects.domain_id = domain.id
+            inner join
+        `cloud`.`project_account` ON projects.id = project_account.project_id
+            and project_account.account_role = 'Admin'
+            inner join
+        `cloud`.`account` ON account.id = project_account.account_id
+            left join
+        `cloud`.`project_account` pacct ON projects.id = pacct.project_id;
diff --git a/server/src/main/java/com/cloud/api/ApiDBUtils.java b/server/src/main/java/com/cloud/api/ApiDBUtils.java
index 40ff827..535eacc 100644
--- a/server/src/main/java/com/cloud/api/ApiDBUtils.java
+++ b/server/src/main/java/com/cloud/api/ApiDBUtils.java
@@ -1771,10 +1771,6 @@ public class ApiDBUtils {
         return s_projectJoinDao.newProjectResponse(proj);
     }
 
-    public static ProjectResponse fillProjectDetails(ProjectResponse rsp, ProjectJoinVO proj) {
-        return s_projectJoinDao.setProjectResponse(rsp, proj);
-    }
-
     public static List<ProjectJoinVO> newProjectView(Project proj) {
         return s_projectJoinDao.newProjectView(proj);
     }
diff --git a/server/src/main/java/com/cloud/api/query/ViewResponseHelper.java b/server/src/main/java/com/cloud/api/query/ViewResponseHelper.java
index 3ac9c8f..cdc27c0 100644
--- a/server/src/main/java/com/cloud/api/query/ViewResponseHelper.java
+++ b/server/src/main/java/com/cloud/api/query/ViewResponseHelper.java
@@ -203,11 +203,8 @@ public class ViewResponseHelper {
             if (pData == null) {
                 // first time encountering this vm
                 pData = ApiDBUtils.newProjectResponse(p);
-            } else {
-                // update those  1 to many mapping fields
-                pData = ApiDBUtils.fillProjectDetails(pData, p);
+                prjDataList.put(p.getId(), pData);
             }
-            prjDataList.put(p.getId(), pData);
         }
         return new ArrayList<ProjectResponse>(prjDataList.values());
     }
diff --git a/server/src/main/java/com/cloud/api/query/dao/ProjectJoinDao.java b/server/src/main/java/com/cloud/api/query/dao/ProjectJoinDao.java
index 9eeb8aa..0142069 100644
--- a/server/src/main/java/com/cloud/api/query/dao/ProjectJoinDao.java
+++ b/server/src/main/java/com/cloud/api/query/dao/ProjectJoinDao.java
@@ -28,8 +28,6 @@ public interface ProjectJoinDao extends GenericDao<ProjectJoinVO, Long> {
 
     ProjectResponse newProjectResponse(ProjectJoinVO proj);
 
-    ProjectResponse setProjectResponse(ProjectResponse rsp, ProjectJoinVO proj);
-
     List<ProjectJoinVO> newProjectView(Project proj);
 
     List<ProjectJoinVO> searchByIds(Long... ids);
diff --git a/server/src/main/java/com/cloud/api/query/dao/ProjectJoinDaoImpl.java b/server/src/main/java/com/cloud/api/query/dao/ProjectJoinDaoImpl.java
index 25598b3..970783b 100644
--- a/server/src/main/java/com/cloud/api/query/dao/ProjectJoinDaoImpl.java
+++ b/server/src/main/java/com/cloud/api/query/dao/ProjectJoinDaoImpl.java
@@ -32,6 +32,7 @@ import com.cloud.api.query.vo.AccountJoinVO;
 import com.cloud.api.query.vo.ProjectJoinVO;
 import com.cloud.api.query.vo.ResourceTagJoinVO;
 import com.cloud.projects.Project;
+import com.cloud.server.ResourceTag.ResourceObjectType;
 import com.cloud.user.Account;
 import com.cloud.user.dao.AccountDao;
 import com.cloud.utils.db.GenericDaoBase;
@@ -81,12 +82,9 @@ public class ProjectJoinDaoImpl extends GenericDaoBase<ProjectJoinVO, Long> impl
         response.setOwner(proj.getOwner());
 
         // update tag information
-        Long tag_id = proj.getTagId();
-        if (tag_id != null && tag_id.longValue() > 0) {
-            ResourceTagJoinVO vtag = ApiDBUtils.findResourceTagViewById(tag_id);
-            if (vtag != null) {
-                response.addTag(ApiDBUtils.newResourceTagResponse(vtag, false));
-            }
+        List<ResourceTagJoinVO> tags = ApiDBUtils.listResourceTagViewByResourceUUID(proj.getUuid(), ResourceObjectType.Project);
+        for (ResourceTagJoinVO vtag : tags) {
+            response.addTag(ApiDBUtils.newResourceTagResponse(vtag, false));
         }
 
         //set resource limit/count information for the project (by getting the info of the project's account)
@@ -100,19 +98,6 @@ public class ProjectJoinDaoImpl extends GenericDaoBase<ProjectJoinVO, Long> impl
     }
 
     @Override
-    public ProjectResponse setProjectResponse(ProjectResponse rsp, ProjectJoinVO proj) {
-        // update tag information
-        Long tag_id = proj.getTagId();
-        if (tag_id != null && tag_id.longValue() > 0) {
-            ResourceTagJoinVO vtag = ApiDBUtils.findResourceTagViewById(tag_id);
-            if (vtag != null) {
-                rsp.addTag(ApiDBUtils.newResourceTagResponse(vtag, false));
-            }
-        }
-        return rsp;
-    }
-
-    @Override
     public List<ProjectJoinVO> newProjectView(Project proj) {
         SearchCriteria<ProjectJoinVO> sc = prjIdSearch.create();
         sc.setParameters("id", proj.getId());
diff --git a/server/src/main/java/com/cloud/api/query/vo/ProjectJoinVO.java b/server/src/main/java/com/cloud/api/query/vo/ProjectJoinVO.java
index 32488ff..b17c9ff 100644
--- a/server/src/main/java/com/cloud/api/query/vo/ProjectJoinVO.java
+++ b/server/src/main/java/com/cloud/api/query/vo/ProjectJoinVO.java
@@ -29,7 +29,6 @@ import org.apache.cloudstack.api.Identity;
 import org.apache.cloudstack.api.InternalIdentity;
 
 import com.cloud.projects.Project.State;
-import com.cloud.server.ResourceTag.ResourceObjectType;
 import com.cloud.utils.db.GenericDao;
 
 @Entity
@@ -77,37 +76,6 @@ public class ProjectJoinVO extends BaseViewVO implements InternalIdentity, Ident
     @Column(name = "domain_path")
     private String domainPath;
 
-    @Column(name = "tag_id")
-    private long tagId;
-
-    @Column(name = "tag_uuid")
-    private String tagUuid;
-
-    @Column(name = "tag_key")
-    private String tagKey;
-
-    @Column(name = "tag_value")
-    private String tagValue;
-
-    @Column(name = "tag_domain_id")
-    private long tagDomainId;
-
-    @Column(name = "tag_account_id")
-    private long tagAccountId;
-
-    @Column(name = "tag_resource_id")
-    private long tagResourceId;
-
-    @Column(name = "tag_resource_uuid")
-    private String tagResourceUuid;
-
-    @Column(name = "tag_resource_type")
-    @Enumerated(value = EnumType.STRING)
-    private ResourceObjectType tagResourceType;
-
-    @Column(name = "tag_customer")
-    private String tagCustomer;
-
     @Column(name = "project_account_id")
     private long projectAccountId;
 
@@ -164,46 +132,6 @@ public class ProjectJoinVO extends BaseViewVO implements InternalIdentity, Ident
         return owner;
     }
 
-    public long getTagId() {
-        return tagId;
-    }
-
-    public String getTagUuid() {
-        return tagUuid;
-    }
-
-    public String getTagKey() {
-        return tagKey;
-    }
-
-    public String getTagValue() {
-        return tagValue;
-    }
-
-    public long getTagDomainId() {
-        return tagDomainId;
-    }
-
-    public long getTagAccountId() {
-        return tagAccountId;
-    }
-
-    public long getTagResourceId() {
-        return tagResourceId;
-    }
-
-    public String getTagResourceUuid() {
-        return tagResourceUuid;
-    }
-
-    public ResourceObjectType getTagResourceType() {
-        return tagResourceType;
-    }
-
-    public String getTagCustomer() {
-        return tagCustomer;
-    }
-
     public long getAccountId() {
         return accountId;
     }