Skip to content

Commit 452b48e

Browse files
ustcweizhouyadvr
authored andcommitted
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
1 parent 4c28a2b commit 452b48e

6 files changed

Lines changed: 36 additions & 102 deletions

File tree

engine/schema/src/main/resources/META-INF/db/schema-41200to41300.sql

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,34 @@ CREATE VIEW `cloud`.`data_center_view` AS
7373
left join
7474
`cloud`.`dedicated_resources` ON data_center.id = dedicated_resources.data_center_id
7575
left join
76-
`cloud`.`affinity_group` ON dedicated_resources.affinity_group_id = affinity_group.id;
76+
`cloud`.`affinity_group` ON dedicated_resources.affinity_group_id = affinity_group.id;
77+
78+
-- Remove key/value tags from project_view
79+
DROP VIEW IF EXISTS `cloud`.`project_view`;
80+
CREATE VIEW `cloud`.`project_view` AS
81+
select
82+
projects.id,
83+
projects.uuid,
84+
projects.name,
85+
projects.display_text,
86+
projects.state,
87+
projects.removed,
88+
projects.created,
89+
projects.project_account_id,
90+
account.account_name owner,
91+
pacct.account_id,
92+
domain.id domain_id,
93+
domain.uuid domain_uuid,
94+
domain.name domain_name,
95+
domain.path domain_path
96+
from
97+
`cloud`.`projects`
98+
inner join
99+
`cloud`.`domain` ON projects.domain_id = domain.id
100+
inner join
101+
`cloud`.`project_account` ON projects.id = project_account.project_id
102+
and project_account.account_role = 'Admin'
103+
inner join
104+
`cloud`.`account` ON account.id = project_account.account_id
105+
left join
106+
`cloud`.`project_account` pacct ON projects.id = pacct.project_id;

server/src/main/java/com/cloud/api/ApiDBUtils.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,10 +1771,6 @@ public static ProjectResponse newProjectResponse(ProjectJoinVO proj) {
17711771
return s_projectJoinDao.newProjectResponse(proj);
17721772
}
17731773

1774-
public static ProjectResponse fillProjectDetails(ProjectResponse rsp, ProjectJoinVO proj) {
1775-
return s_projectJoinDao.setProjectResponse(rsp, proj);
1776-
}
1777-
17781774
public static List<ProjectJoinVO> newProjectView(Project proj) {
17791775
return s_projectJoinDao.newProjectView(proj);
17801776
}

server/src/main/java/com/cloud/api/query/ViewResponseHelper.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,8 @@ public static List<ProjectResponse> createProjectResponse(ProjectJoinVO... proje
203203
if (pData == null) {
204204
// first time encountering this vm
205205
pData = ApiDBUtils.newProjectResponse(p);
206-
} else {
207-
// update those 1 to many mapping fields
208-
pData = ApiDBUtils.fillProjectDetails(pData, p);
206+
prjDataList.put(p.getId(), pData);
209207
}
210-
prjDataList.put(p.getId(), pData);
211208
}
212209
return new ArrayList<ProjectResponse>(prjDataList.values());
213210
}

server/src/main/java/com/cloud/api/query/dao/ProjectJoinDao.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ public interface ProjectJoinDao extends GenericDao<ProjectJoinVO, Long> {
2828

2929
ProjectResponse newProjectResponse(ProjectJoinVO proj);
3030

31-
ProjectResponse setProjectResponse(ProjectResponse rsp, ProjectJoinVO proj);
32-
3331
List<ProjectJoinVO> newProjectView(Project proj);
3432

3533
List<ProjectJoinVO> searchByIds(Long... ids);

server/src/main/java/com/cloud/api/query/dao/ProjectJoinDaoImpl.java

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.cloud.api.query.vo.ProjectJoinVO;
3333
import com.cloud.api.query.vo.ResourceTagJoinVO;
3434
import com.cloud.projects.Project;
35+
import com.cloud.server.ResourceTag.ResourceObjectType;
3536
import com.cloud.user.Account;
3637
import com.cloud.user.dao.AccountDao;
3738
import com.cloud.utils.db.GenericDaoBase;
@@ -81,12 +82,9 @@ public ProjectResponse newProjectResponse(ProjectJoinVO proj) {
8182
response.setOwner(proj.getOwner());
8283

8384
// update tag information
84-
Long tag_id = proj.getTagId();
85-
if (tag_id != null && tag_id.longValue() > 0) {
86-
ResourceTagJoinVO vtag = ApiDBUtils.findResourceTagViewById(tag_id);
87-
if (vtag != null) {
88-
response.addTag(ApiDBUtils.newResourceTagResponse(vtag, false));
89-
}
85+
List<ResourceTagJoinVO> tags = ApiDBUtils.listResourceTagViewByResourceUUID(proj.getUuid(), ResourceObjectType.Project);
86+
for (ResourceTagJoinVO vtag : tags) {
87+
response.addTag(ApiDBUtils.newResourceTagResponse(vtag, false));
9088
}
9189

9290
//set resource limit/count information for the project (by getting the info of the project's account)
@@ -99,19 +97,6 @@ public ProjectResponse newProjectResponse(ProjectJoinVO proj) {
9997
return response;
10098
}
10199

102-
@Override
103-
public ProjectResponse setProjectResponse(ProjectResponse rsp, ProjectJoinVO proj) {
104-
// update tag information
105-
Long tag_id = proj.getTagId();
106-
if (tag_id != null && tag_id.longValue() > 0) {
107-
ResourceTagJoinVO vtag = ApiDBUtils.findResourceTagViewById(tag_id);
108-
if (vtag != null) {
109-
rsp.addTag(ApiDBUtils.newResourceTagResponse(vtag, false));
110-
}
111-
}
112-
return rsp;
113-
}
114-
115100
@Override
116101
public List<ProjectJoinVO> newProjectView(Project proj) {
117102
SearchCriteria<ProjectJoinVO> sc = prjIdSearch.create();

server/src/main/java/com/cloud/api/query/vo/ProjectJoinVO.java

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import org.apache.cloudstack.api.InternalIdentity;
3030

3131
import com.cloud.projects.Project.State;
32-
import com.cloud.server.ResourceTag.ResourceObjectType;
3332
import com.cloud.utils.db.GenericDao;
3433

3534
@Entity
@@ -77,37 +76,6 @@ public class ProjectJoinVO extends BaseViewVO implements InternalIdentity, Ident
7776
@Column(name = "domain_path")
7877
private String domainPath;
7978

80-
@Column(name = "tag_id")
81-
private long tagId;
82-
83-
@Column(name = "tag_uuid")
84-
private String tagUuid;
85-
86-
@Column(name = "tag_key")
87-
private String tagKey;
88-
89-
@Column(name = "tag_value")
90-
private String tagValue;
91-
92-
@Column(name = "tag_domain_id")
93-
private long tagDomainId;
94-
95-
@Column(name = "tag_account_id")
96-
private long tagAccountId;
97-
98-
@Column(name = "tag_resource_id")
99-
private long tagResourceId;
100-
101-
@Column(name = "tag_resource_uuid")
102-
private String tagResourceUuid;
103-
104-
@Column(name = "tag_resource_type")
105-
@Enumerated(value = EnumType.STRING)
106-
private ResourceObjectType tagResourceType;
107-
108-
@Column(name = "tag_customer")
109-
private String tagCustomer;
110-
11179
@Column(name = "project_account_id")
11280
private long projectAccountId;
11381

@@ -164,46 +132,6 @@ public String getOwner() {
164132
return owner;
165133
}
166134

167-
public long getTagId() {
168-
return tagId;
169-
}
170-
171-
public String getTagUuid() {
172-
return tagUuid;
173-
}
174-
175-
public String getTagKey() {
176-
return tagKey;
177-
}
178-
179-
public String getTagValue() {
180-
return tagValue;
181-
}
182-
183-
public long getTagDomainId() {
184-
return tagDomainId;
185-
}
186-
187-
public long getTagAccountId() {
188-
return tagAccountId;
189-
}
190-
191-
public long getTagResourceId() {
192-
return tagResourceId;
193-
}
194-
195-
public String getTagResourceUuid() {
196-
return tagResourceUuid;
197-
}
198-
199-
public ResourceObjectType getTagResourceType() {
200-
return tagResourceType;
201-
}
202-
203-
public String getTagCustomer() {
204-
return tagCustomer;
205-
}
206-
207135
public long getAccountId() {
208136
return accountId;
209137
}

0 commit comments

Comments
 (0)