diff options
author | Matteo Mara <matteo.mara@sonarsource.com> | 2022-02-23 21:43:23 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2022-02-25 20:02:54 +0000 |
commit | e30eb01b20e62a3365fb66d39e9b88ceb87bb4af (patch) | |
tree | f3b2cbe7232491ca4648a0c407f108db42d52599 /server/sonar-db-dao | |
parent | 97ad45993a48f860cf5957a204bca1fdbe4d7ee4 (diff) | |
download | sonarqube-e30eb01b20e62a3365fb66d39e9b88ceb87bb4af.tar.gz sonarqube-e30eb01b20e62a3365fb66d39e9b88ceb87bb4af.zip |
SONAR-10930 add pagination in activity API
Diffstat (limited to 'server/sonar-db-dao')
4 files changed, 21 insertions, 2 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeActivityDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeActivityDao.java index 494af70c784..38a84512171 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeActivityDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeActivityDao.java @@ -84,6 +84,10 @@ public class CeActivityDao implements Dao { return mapper(dbSession).selectByQuery(query, pagination); } + public int countByQuery(DbSession dbSession, CeTaskQuery query) { + return mapper(dbSession).countByQuery(query); + } + public int countLastByStatusAndMainComponentUuid(DbSession dbSession, CeActivityDto.Status status, @Nullable String mainComponentUuid) { return mapper(dbSession).countLastByStatusAndMainComponentUuid(status, mainComponentUuid); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeActivityMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeActivityMapper.java index 78a801c2bc7..156ae996fda 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeActivityMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeActivityMapper.java @@ -36,6 +36,8 @@ public interface CeActivityMapper { List<CeActivityDto> selectNewerThan(@Param("afterDate") long afterDate); + int countByQuery(@Param("query") CeTaskQuery query); + int countLastByStatusAndMainComponentUuid(@Param("status") CeActivityDto.Status status, @Nullable @Param("mainComponentUuid") String mainComponentUuid); void insert(CeActivityDto dto); 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 3d4edfb5049..1e86d6b7118 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 @@ -55,13 +55,20 @@ public class CeQueueDao implements Dao { } public List<CeQueueDto> selectByQueryInDescOrder(DbSession dbSession, CeTaskQuery query, int pageSize) { + return selectByQueryInDescOrder(dbSession, query, 1, pageSize); + } + + public List<CeQueueDto> selectByQueryInDescOrder(DbSession dbSession, CeTaskQuery query, int page, int pageSize) { if (query.isShortCircuitedByMainComponentUuids() || query.isOnlyCurrents() || query.getMaxExecutedAt() != null) { return emptyList(); } - return mapper(dbSession).selectByQueryInDescOrder(query, new RowBounds(0, pageSize)); + int offset = (page - 1) * pageSize; + int limit = page * pageSize; + + return mapper(dbSession).selectByQueryInDescOrder(query, new RowBounds(offset, limit)); } public int countByQuery(DbSession dbSession, CeTaskQuery query) { diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml index f94c83b5ffc..261f886da0a 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml @@ -152,7 +152,13 @@ where ca.created_at > #{afterDate,jdbcType=BIGINT} </select> - + + <select id="countByQuery" parameterType="map" resultType="int"> + select + count(1) + <include refid="sqlSelectByQuery" /> + </select> + <select id="countLastByStatusAndMainComponentUuid" resultType="int"> select count(1) |