final List<User> followers = getFollowers(user.getFollowersStr());
user.setFollowers(followers);
if (user.getPassword() != null && StringUtils.isBlank(user.getPassword())) {
user.setPassword(null);
}
final User existing = userRepository.findOneByUserId(user.getUserId());
if (existing != null) {
// First expire existing followers.
final List<User> existingFollowers = existing.getFollowers();
if (existingFollowers != null) {
for (User eachFollower : existingFollowers) {
userCache.evict(eachFollower.getUserId());
}
}
user = existing.merge(user);
}
User createdUser = userRepository.save(user);
// Then expires new followers so that new followers info can be loaded.
for (User eachFollower : followers) {
userCache.evict(eachFollower.getUserId());
}
prepareUserEnv(createdUser);