Fixed wrong PageTotalNum, and removed redundant SQL LEFT JOIN

This commit is contained in:
DAI Mingchen
2024-08-29 13:09:56 +08:00
repo.diff.parent 2f5dfd3196
repo.diff.commit 624032c3c5

repo.diff.view_file

@@ -57,12 +57,10 @@ func GetUserDevcontainersList(ctx context.Context, opts *DevcontainersVO.SearchD
/*
SELECT COUNT(*)
FROM devstar_devcontainer
LEFT JOIN repository ON devstar_devcontainer.repo_id = repository.id
WHERE devstar_devcontainer.user_id = #{opts.Actor.ID}
WHERE user_id = #{opts.Actor.ID}
*/
resultDevContainerListVO.ItemTotalNum, err = sess.
Table("devstar_devcontainer").
Join("LEFT", "repository", "devstar_devcontainer.repo_id = repository.id").
Where(sqlCondition).
Count()
if err != nil {
@@ -78,7 +76,10 @@ func GetUserDevcontainersList(ctx context.Context, opts *DevcontainersVO.SearchD
// 2.3 计算分页参数
totalRecords := resultDevContainerListVO.ItemTotalNum
pageSize := int64(resultDevContainerListVO.PageSize)
resultDevContainerListVO.PageTotalNum += int(totalRecords/pageSize) + 1
resultDevContainerListVO.PageTotalNum = int(totalRecords / pageSize)
if totalRecords%pageSize > 0 {
resultDevContainerListVO.PageTotalNum += 1
}
// 2.3 数据库带条件分页查询
resultDevContainerListVO.DevContainers = make([]DevcontainersVO.DevContainerItemVO, 0, opts.PaginationOptions.PageSize)