Skip to content

Commit

Permalink
Use countDistinctTopicNameByAclTypeAndTeamIdAndTenantId rather than s…
Browse files Browse the repository at this point in the history
…elect all

Signed-off-by: Sergey Nuyanzin <[email protected]>
  • Loading branch information
snuyanzin authored Jan 17, 2024
1 parent 090959a commit 6f47f18
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -424,23 +424,13 @@ public List<Topic> selectSyncTopics(String env, Integer teamId, int tenantId) {

public DashboardStats getDashboardStats(Integer teamId, int tenantId) {
DashboardStats dashboardStats = new DashboardStats();
int countProducers = 0, countConsumers = 0;
List<Acl> acls =
aclRepo.findAllByAclTypeAndTeamIdAndTenantId(AclType.PRODUCER.value, teamId, tenantId);
List<String> topicList = new ArrayList<>();
if (acls != null) {
acls.forEach(a -> topicList.add(a.getTopicname()));
countProducers = (int) topicList.stream().distinct().count();
}
dashboardStats.setProducerCount(countProducers);

acls = aclRepo.findAllByAclTypeAndTeamIdAndTenantId(AclType.CONSUMER.value, teamId, tenantId);
List<String> topicListCons = new ArrayList<>();
if (acls != null) {
acls.forEach(a -> topicListCons.add(a.getTopicname()));
countConsumers = (int) topicListCons.stream().distinct().count();
}
dashboardStats.setConsumerCount(countConsumers);
dashboardStats.setProducerCount(
aclRepo.countDistinctTopicNameByAclTypeAndTeamIdAndTenantId(
AclType.PRODUCER.value, teamId, tenantId));

dashboardStats.setConsumerCount(
aclRepo.countDistinctTopicNameByAclTypeAndTeamIdAndTenantId(
AclType.CONSUMER.value, teamId, tenantId));

dashboardStats.setTeamMembersCount(userInfoRepo.countByTeamIdAndTenantId(teamId, tenantId));

Expand Down
7 changes: 7 additions & 0 deletions core/src/main/java/io/aiven/klaw/repository/AclRepo.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ public interface AclRepo extends CrudRepository<Acl, AclID> {

List<Acl> findAllByAclTypeAndTeamIdAndTenantId(String topicType, Integer teamId, int tenantId);

@Query(
value =
"SELECT count(DISTINCT topicname) FROM kwacls WHERE topictype = :topicType AND teamid = :teamId AND tenantid = :tenantId",
nativeQuery = true)
int countDistinctTopicNameByAclTypeAndTeamIdAndTenantId(
String topicType, Integer teamId, int tenantId);

List<Acl> findAllByAclTypeAndTenantId(String topicType, int tenantId);

List<Acl> findAllByEnvironmentAndTopicnameAndTenantId(
Expand Down

0 comments on commit 6f47f18

Please sign in to comment.