MembershipWriter.removeMembers writes back too often
@@ -214,11 +214,14 @@ public class MembershipWriter {
PropertyState refs = t.getProperty(UserConstants.REP_MEMBERS);
if (refs != null) {
PropertyBuilder<String> prop = PropertyBuilder.copy(Type.WEAKREFERENCE, refs);
- Iterator<Map.Entry<String,String>> memberEntries = memberIds.entrySet().iterator();
- while (memberEntries.hasNext()) {
- String memberContentId = memberEntries.next().getKey();
+ Iterator<Map.Entry<String,String>> it = memberIds.entrySet().iterator();
+ while (it.hasNext() && !prop.isEmpty()) {
+ String memberContentId = it.next().getKey();
if (prop.hasValue(memberContentId)) {
prop.removeValue(memberContentId);
+ it.remove();
+ }
+ }
if (prop.isEmpty()) {
if (t == groupTree) {
t.removeProperty(UserConstants.REP_MEMBERS);
@@ -228,9 +231,6 @@ public class MembershipWriter {
} else {
t.setProperty(prop.getPropertyState());
}
- memberEntries.remove();
- }
- }
}
}
return Sets.newHashSet(memberIds.values());
