From 3a6d71993dfcde510c7852a0291961d0aa89ad74 Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Tue, 28 Mar 2017 16:06:03 +0200 Subject: [PATCH] SONAR-9040 fix pagination in CeQueueDao#selectEligibleForPeek --- .../main/java/org/sonar/db/ce/CeQueueDao.java | 5 +- .../java/org/sonar/db/ce/CeQueueMapper.java | 3 +- .../org/sonar/db/ce/CeQueueMapper.xml | 50 +++++++++++++++++-- 3 files changed, 51 insertions(+), 7 deletions(-) diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeQueueDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeQueueDao.java index 73e90cfcfda..dc94239d882 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeQueueDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeQueueDao.java @@ -26,6 +26,7 @@ import org.apache.ibatis.session.RowBounds; import org.sonar.api.utils.System2; import org.sonar.db.Dao; import org.sonar.db.DbSession; +import org.sonar.db.Pagination; import static java.util.Collections.emptyList; import static org.sonar.db.ce.CeQueueDto.Status.IN_PROGRESS; @@ -33,7 +34,7 @@ import static org.sonar.db.ce.CeQueueDto.Status.PENDING; public class CeQueueDao implements Dao { - private static final RowBounds ONE_ROW_LIMIT = new RowBounds(0, 1); + private static final Pagination ONE_RESULT_PAGINATION = Pagination.forPage(1).andSize(1); private final System2 system2; @@ -110,7 +111,7 @@ public class CeQueueDao implements Dao { } public Optional peek(DbSession session, String workerUuid) { - List eligibles = mapper(session).selectEligibleForPeek(ONE_ROW_LIMIT); + List eligibles = mapper(session).selectEligibleForPeek(ONE_RESULT_PAGINATION); if (eligibles.isEmpty()) { return Optional.absent(); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeQueueMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeQueueMapper.java index b89569f01f4..d605e2b8be1 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeQueueMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeQueueMapper.java @@ -24,6 +24,7 @@ import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.session.RowBounds; +import org.sonar.db.Pagination; public interface CeQueueMapper { @@ -35,7 +36,7 @@ public interface CeQueueMapper { int countByQuery(@Param("query") CeTaskQuery query); - List selectEligibleForPeek(RowBounds rowBounds); + List selectEligibleForPeek(@Param("pagination") Pagination pagination); @CheckForNull CeQueueDto selectByUuid(@Param("uuid") String uuid); diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/ce/CeQueueMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/ce/CeQueueMapper.xml index 657c8a9d526..2d1f28c90c9 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/ce/CeQueueMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/ce/CeQueueMapper.xml @@ -114,8 +114,45 @@ + + + + + + + cq.uuid as "uuid", + cq.execution_count as "executionCount", + cq.created_at as "created_at", + cq.id as "id" + + + from ce_queue cq where @@ -129,8 +166,13 @@ cq.component_uuid=cq2.component_uuid and cq2.status <> 'PENDING' ) - - + + + + order by + created_at asc, + id asc + insert into ce_queue -- 2.39.5