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
This commit is contained in:
Wei Zhou 2019-07-03 08:11:53 +02:00 committed by Rohit Yadav
parent 4c28a2bcaa
commit 452b48ea0c
6 changed files with 36 additions and 102 deletions

View File

@ -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;
`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;

View File

@ -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);
}

View File

@ -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());
}

View File

@ -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);

View File

@ -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)
@ -99,19 +97,6 @@ public class ProjectJoinDaoImpl extends GenericDaoBase<ProjectJoinVO, Long> impl
return response;
}
@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();

View File

@ -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;
}