Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,13 @@ protected void postUpdate(T original, T updated) {
}
}

@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,8 @@ private void updateUsers(Team origTeam, Team updatedTeam) {
origUsers,
updatedUsers,
false);

updatedTeam.setUserCount(updatedUsers.size());
}

private void updateDefaultRoles(Team origTeam, Team updatedTeam) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@
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;
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;
Expand Down Expand Up @@ -709,6 +711,14 @@ private void updateTeams(User original, User updated) {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@
}
}
},
"userCount" : {
"type" : "long"
},
"parents": {
"properties": {
"id": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@
}
}
},
"userCount" : {
"type" : "long"
},
"parents": {
"properties": {
"id": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@
}
}
},
"userCount" : {
"type" : "long"
},
"parents": {
"properties": {
"id": {
Expand Down
Loading