GEN-1937 : Fix - User count doesn’t update on adding to the team while using search (#18516)

This commit is contained in:
sonika-shah 2024-11-06 16:13:23 +05:30 committed by GitHub
parent 3dcbeb469f
commit 1ade1d4eb6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 28 additions and 0 deletions

View File

@ -971,6 +971,13 @@ public abstract class EntityRepository<T extends EntityInterface> {
}
}
@SuppressWarnings("unused")
protected void postUpdate(T updated) {
if (supportsSearch) {
searchRepository.updateEntity(updated);
}
}
@Transaction
public final PutResponse<T> update(UriInfo uriInfo, T original, T updated) {
// Get all the fields in the original entity that can be updated during PUT operation

View File

@ -798,6 +798,8 @@ public class TeamRepository extends EntityRepository<Team> {
origUsers,
updatedUsers,
false);
updatedTeam.setUserCount(updatedUsers.size());
}
private void updateDefaultRoles(Team origTeam, Team updatedTeam) {

View File

@ -36,6 +36,7 @@ import java.util.Set;
import java.util.TreeSet;
import java.util.UUID;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.ws.rs.core.SecurityContext;
import javax.ws.rs.core.UriInfo;
import lombok.extern.slf4j.Slf4j;
@ -43,6 +44,7 @@ import org.apache.commons.csv.CSVPrinter;
import org.apache.commons.csv.CSVRecord;
import org.jdbi.v3.sqlobject.transaction.Transaction;
import org.openmetadata.csv.EntityCsv;
import org.openmetadata.schema.EntityInterface;
import org.openmetadata.schema.api.teams.CreateTeam.TeamType;
import org.openmetadata.schema.api.teams.CreateUser;
import org.openmetadata.schema.entity.teams.AuthenticationMechanism;
@ -709,6 +711,14 @@ public class UserRepository extends EntityRepository<User> {
List<EntityReference> deleted = new ArrayList<>();
recordListChange(
TEAMS_FIELD, origTeams, updatedTeams, added, deleted, EntityUtil.entityReferenceMatch);
// Update users and userCount in team search index
Stream.concat(added.stream(), deleted.stream())
.forEach(
teamRef -> {
EntityInterface team = Entity.getEntity(teamRef, "id,userCount", Include.ALL);
searchRepository.updateEntity(team);
});
}
private void updatePersonas(User original, User updated) {

View File

@ -192,6 +192,9 @@
}
}
},
"userCount" : {
"type" : "long"
},
"parents": {
"properties": {
"id": {

View File

@ -188,6 +188,9 @@
}
}
},
"userCount" : {
"type" : "long"
},
"parents": {
"properties": {
"id": {

View File

@ -179,6 +179,9 @@
}
}
},
"userCount" : {
"type" : "long"
},
"parents": {
"properties": {
"id": {