From af4e544bb6bc2572ddcc37c8597c34b6dd5a35b0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Mon, 5 Dec 2016 17:35:35 +0100 Subject: [PATCH] SONAR-8442 do not do a select to keep ce_activity.is_key up to date --- .../main/java/org/sonar/db/ce/CeActivityDao.java | 13 +++++-------- .../java/org/sonar/db/ce/CeActivityMapper.java | 5 ----- .../org/sonar/db/ce/CeActivityMapper.xml | 15 --------------- 3 files changed, 5 insertions(+), 28 deletions(-) diff --git a/sonar-db/src/main/java/org/sonar/db/ce/CeActivityDao.java b/sonar-db/src/main/java/org/sonar/db/ce/CeActivityDao.java index 5a7cada22da..ec07a732ff8 100644 --- a/sonar-db/src/main/java/org/sonar/db/ce/CeActivityDao.java +++ b/sonar-db/src/main/java/org/sonar/db/ce/CeActivityDao.java @@ -24,7 +24,6 @@ import java.util.Collections; import java.util.List; import java.util.Set; import javax.annotation.Nullable; -import org.apache.ibatis.session.RowBounds; import org.sonar.api.utils.System2; import org.sonar.db.Dao; import org.sonar.db.DbSession; @@ -46,15 +45,13 @@ public class CeActivityDao implements Dao { public void insert(DbSession dbSession, CeActivityDto dto) { dto.setCreatedAt(system2.now()); dto.setUpdatedAt(system2.now()); - dto.setIsLast(false); - mapper(dbSession).insert(dto); + dto.setIsLast(dto.getStatus() != CeActivityDto.Status.CANCELED); - List uuids = mapper(dbSession).selectUuidsOfRecentlyCreatedByIsLastKey(dto.getIsLastKey(), new RowBounds(0, 1)); - // should never be empty, as a row was just inserted! - if (!uuids.isEmpty()) { - mapper(dbSession).updateIsLastToFalseForLastKey(dto.getIsLastKey(), dto.getUpdatedAt()); - mapper(dbSession).updateIsLastToTrueForUuid(uuids.get(0), dto.getUpdatedAt()); + CeActivityMapper ceActivityMapper = mapper(dbSession); + if (dto.getIsLast()) { + ceActivityMapper.updateIsLastToFalseForLastKey(dto.getIsLastKey(), dto.getUpdatedAt()); } + ceActivityMapper.insert(dto); } public List selectOlderThan(DbSession dbSession, long beforeDate) { diff --git a/sonar-db/src/main/java/org/sonar/db/ce/CeActivityMapper.java b/sonar-db/src/main/java/org/sonar/db/ce/CeActivityMapper.java index ea5d9e9c885..07015f5335f 100644 --- a/sonar-db/src/main/java/org/sonar/db/ce/CeActivityMapper.java +++ b/sonar-db/src/main/java/org/sonar/db/ce/CeActivityMapper.java @@ -23,12 +23,9 @@ import java.util.List; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.apache.ibatis.annotations.Param; -import org.apache.ibatis.session.RowBounds; public interface CeActivityMapper { - List selectUuidsOfRecentlyCreatedByIsLastKey(@Param("isLastKey") String isLastKey, RowBounds rowBounds); - @CheckForNull CeActivityDto selectByUuid(@Param("uuid") String uuid); @@ -44,7 +41,5 @@ public interface CeActivityMapper { void updateIsLastToFalseForLastKey(@Param("isLastKey") String isLastKey, @Param("updatedAt") long updatedAt); - void updateIsLastToTrueForUuid(@Param("uuid") String uuid, @Param("updatedAt") long updatedAt); - void deleteByUuids(@Param("uuids") List uuids); } diff --git a/sonar-db/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml b/sonar-db/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml index c0281f1b9d9..c4226b8efb2 100644 --- a/sonar-db/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml @@ -44,14 +44,6 @@ where ca.uuid=#{uuid} - -