Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(controller): page not working #2540

Merged
merged 3 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ public DatasetService(ProjectService projectService, DatasetMapper datasetMapper


public PageInfo<DatasetVo> listDataset(DatasetQuery query, PageParams pageParams) {
PageHelper.startPage(pageParams.getPageNum(), pageParams.getPageSize());
Long projectId = projectService.getProjectId(query.getProjectUrl());
Long userId = userService.getUserId(query.getOwner());
PageHelper.startPage(pageParams.getPageNum(), pageParams.getPageSize());
List<DatasetEntity> entities = datasetMapper.list(projectId,
query.getNamePrefix(), userId, null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
import ai.starwhale.mlops.domain.evaluation.mapper.ViewConfigMapper;
import ai.starwhale.mlops.domain.evaluation.po.ViewConfigEntity;
import ai.starwhale.mlops.domain.job.JobDao;
import ai.starwhale.mlops.domain.job.bo.Job;
import ai.starwhale.mlops.domain.job.converter.JobConverter;
import ai.starwhale.mlops.domain.job.po.JobEntity;
import ai.starwhale.mlops.domain.job.status.JobStatusMachine;
import ai.starwhale.mlops.domain.project.ProjectService;
import ai.starwhale.mlops.domain.user.UserService;
Expand Down Expand Up @@ -112,14 +112,14 @@ public Boolean createViewConfig(String projectUrl, ConfigRequest configRequest)

public PageInfo<SummaryVo> listEvaluationSummary(String projectUrl,
SummaryFilter summaryFilter, PageParams pageParams) {
PageHelper.startPage(pageParams.getPageNum(), pageParams.getPageSize());
Long projectId = projectService.getProjectId(projectUrl);
List<Job> jobs = jobDao.listJobs(projectId, null);
PageHelper.startPage(pageParams.getPageNum(), pageParams.getPageSize());
var jobs = jobDao.listJobs(projectId, null);
return PageUtil.toPageInfo(jobs, this::toSummary);
}


private SummaryVo toSummary(Job job) {
private SummaryVo toSummary(JobEntity job) {
if (summaryCache.containsKey(job.getId())) {
return summaryCache.get(job.getId());
}
Expand All @@ -129,7 +129,7 @@ private SummaryVo toSummary(Job job) {
.id(jobVo.getId())
.uuid(jobVo.getUuid())
.projectId(idConvertor.convert(job.getProject().getId()))
.projectName(job.getProject().getName())
.projectName(job.getProject().getProjectName())
.modelName(jobVo.getModelName())
.modelVersion(jobVo.getModelVersion())
.datasets(StrUtil.join(",", jobVo.getDatasets()))
Expand All @@ -145,7 +145,7 @@ private SummaryVo toSummary(Job job) {
.build();

// only cache the jobs which have the final status
if (jobStatusMachine.isFinal(job.getStatus())) {
if (jobStatusMachine.isFinal(job.getJobStatus())) {
summaryCache.put(job.getId(), summaryVo);
}
return summaryVo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,8 @@ private JobEntity convertFromFlatten(JobFlattenEntity flattenEntity) {
}


public List<Job> listJobs(Long projectId, Long modelId) {
return jobMapper.listJobs(projectId, modelId)
.stream()
.map(jobBoConverter::fromEntity)
.collect(Collectors.toList());
public List<JobEntity> listJobs(Long projectId, Long modelId) {
return jobMapper.listJobs(projectId, modelId);
}

public List<Job> findJobByStatusIn(List<JobStatus> jobStatuses) {
Expand Down Expand Up @@ -177,6 +174,14 @@ public Job findJob(String jobUrl) {
}
}

public JobEntity findJobEntity(String jobUrl) {
if (idConvertor.isId(jobUrl)) {
return jobMapper.findJobById(idConvertor.revert(jobUrl));
} else {
return jobMapper.findJobByUuid(jobUrl);
}
}

public boolean updateJobPinStatus(String jobUrl, boolean pinned) {
Date pinnedTime = pinned ? Date.from(Instant.now()) : null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ public JobService(
}

public PageInfo<JobVo> listJobs(String projectUrl, Long modelId, PageParams pageParams) {
PageHelper.startPage(pageParams.getPageNum(), pageParams.getPageSize());
Long projectId = projectService.getProjectId(projectUrl);
List<Job> jobEntities = jobDao.listJobs(projectId, modelId);
PageHelper.startPage(pageParams.getPageNum(), pageParams.getPageSize());
var jobEntities = jobDao.listJobs(projectId, modelId);
return PageUtil.toPageInfo(jobEntities, jobConvertor::convert);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public interface StepMapper {
+ " values (#{step.uuid}, #{step.name}, #{step.jobId}, #{step.lastStepId}, #{step.status}, "
+ " #{step.concurrency}, #{step.taskNum}, #{step.poolInfo})")
@Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "id")
void save(@Param("step") StepEntity stepEntity);
int save(@Param("step") StepEntity stepEntity);

@Select("select id, step_uuid as uuid, step_name as name, job_id, last_step_id, step_status as status,"
+ " finished_time, started_time, created_time, modified_time, concurrency, task_num, pool_info from step"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ public ModelService(
}

public PageInfo<ModelVo> listModel(ModelQuery query, PageParams pageParams) {
PageHelper.startPage(pageParams.getPageNum(), pageParams.getPageSize());
Long projectId = projectService.getProjectId(query.getProjectUrl());
Long userId = userService.getUserId(query.getOwner());
PageHelper.startPage(pageParams.getPageNum(), pageParams.getPageSize());
List<ModelEntity> entities = modelMapper.list(projectId, query.getNamePrefix(), userId, null);
return PageUtil.toPageInfo(entities, entity -> {
ModelVo vo = modelVoConverter.convert(entity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ public RuntimeService(RuntimeMapper runtimeMapper,
}

public PageInfo<RuntimeVo> listRuntime(RuntimeQuery runtimeQuery, PageParams pageParams) {
PageHelper.startPage(pageParams.getPageNum(), pageParams.getPageSize());
Long projectId = projectService.getProjectId(runtimeQuery.getProjectUrl());
Long userId = userService.getUserId(runtimeQuery.getOwner());
PageHelper.startPage(pageParams.getPageNum(), pageParams.getPageSize());
List<RuntimeEntity> entities = runtimeMapper.list(projectId, runtimeQuery.getNamePrefix(), userId, null);

return PageUtil.toPageInfo(entities, rt -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import ai.starwhale.mlops.api.protocol.task.TaskVo;
import ai.starwhale.mlops.common.IdConverter;
import ai.starwhale.mlops.common.PageParams;
import ai.starwhale.mlops.common.util.PageUtil;
import ai.starwhale.mlops.domain.job.JobDao;
import ai.starwhale.mlops.domain.job.bo.Job;
import ai.starwhale.mlops.domain.task.bo.ResultPath;
import ai.starwhale.mlops.domain.task.converter.TaskConverter;
import ai.starwhale.mlops.domain.task.mapper.TaskMapper;
Expand Down Expand Up @@ -63,16 +63,16 @@ public TaskService(TaskConverter taskConvertor, TaskMapper taskMapper,
}

public PageInfo<TaskVo> listTasks(String jobUrl, PageParams pageParams) {
var job = jobDao.findJobEntity(jobUrl);
PageHelper.startPage(pageParams.getPageNum(), pageParams.getPageSize());
Job job = jobDao.findJob(jobUrl);
List<TaskVo> tasks = taskMapper.listTasks(job.getId()).stream().map(taskConvertor::convert)
.peek(taskVo -> {
if (!StringUtils.hasText(taskVo.getResourcePool())) {
taskVo.setResourcePool(job.getResourcePool().getName());
}
})
.collect(Collectors.toList());
return PageInfo.of(tasks);
var entities = taskMapper.listTasks(job.getId());
return PageUtil.toPageInfo(entities, entity -> {
var vo = taskConvertor.convert(entity);
if (!StringUtils.hasText(vo.getResourcePool())) {
vo.setResourcePool(job.getResourcePool());
}
return vo;
});

}

Expand Down
Loading