From 0eb2911cd30df0435dc78850a08303a1ea435f36 Mon Sep 17 00:00:00 2001 From: Alain Kermis Date: Tue, 14 Mar 2023 16:15:16 +0100 Subject: [PATCH] SONAR-18589 Fix system info user count --- .../src/it/java/org/sonar/db/user/UserDaoIT.java | 10 ++++++++++ .../src/main/java/org/sonar/db/user/UserDao.java | 4 ++++ .../src/main/java/org/sonar/db/user/UserMapper.java | 2 ++ .../main/resources/org/sonar/db/user/UserMapper.xml | 4 ++++ 4 files changed, 20 insertions(+) diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/user/UserDaoIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/user/UserDaoIT.java index d9bb04089db..1b9d348c1fb 100644 --- a/server/sonar-db-dao/src/it/java/org/sonar/db/user/UserDaoIT.java +++ b/server/sonar-db-dao/src/it/java/org/sonar/db/user/UserDaoIT.java @@ -407,6 +407,16 @@ public class UserDaoIT { assertThat(underTest.countSonarlintWeeklyUsers(db.getSession())).isEqualTo(2); } + @Test + public void count_active_users() { + db.users().insertUser(); + db.users().insertUser(); + db.users().insertUser(); + db.users().insertUser(c -> c.setActive(false)); + + assertThat(underTest.countActiveUsers(db.getSession())).isEqualTo(3); + } + @Test public void clean_user_homepage() { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDao.java index 442edf73596..8387c648d9b 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDao.java @@ -189,6 +189,10 @@ public class UserDao implements Dao { return mapper(dbSession).countActiveSonarlintUsers(threshold); } + public long countActiveUsers(DbSession dbSession) { + return mapper(dbSession).countActiveUsers(); + } + public void scrollByUuids(DbSession dbSession, Collection uuids, Consumer consumer) { UserMapper mapper = mapper(dbSession); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserMapper.java index 3bc198edb01..8676a8a04a2 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserMapper.java @@ -81,4 +81,6 @@ public interface UserMapper { void clearHomepage(@Param("login") String login, @Param("now") long now); long countActiveSonarlintUsers(@Param("sinceDate") long sinceDate); + + long countActiveUsers(); } diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/user/UserMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/user/UserMapper.xml index abab22c8757..2f5ae52d2ec 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/user/UserMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/user/UserMapper.xml @@ -269,4 +269,8 @@ where last_sonarlint_connection > #{sinceDate,jdbcType=BIGINT} + + -- 2.39.5