From 46dc0f0590c60abfe479c95f17f11b552ad070a9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Mon, 5 Dec 2016 17:33:36 +0100 Subject: [PATCH] SONAR-8447 avoid select to key ce_activity.is_key up to date --- .../main/java/org/sonar/db/ce/CeActivityDao.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 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 91f155ee3ca..3893059b645 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 @@ -23,7 +23,6 @@ import com.google.common.base.Optional; import java.util.Collections; import java.util.List; 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; @@ -43,15 +42,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) { -- 2.39.5