Skip to content

Commit

Permalink
Turn off uniqueness checking for REPLACE deltas
Browse files Browse the repository at this point in the history
This is an attempt to improve performance of large groups processing:
before more serious solution is implemented, as per MID-5889.
  • Loading branch information
mederly committed Oct 28, 2019
1 parent 46e5251 commit c351863
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 3 deletions.
Expand Up @@ -272,12 +272,20 @@ public interface Item<V extends PrismValue, D extends ItemDefinition> extends It

/**
* Adds given values, with the same semantics as repeated add(..) calls.
* For equality testing uses give strategy.
* For equality testing uses given strategy.
*
* @return true if this item changed as a result of the call (i.e. if at least one value was really added)
*/
boolean addAll(Collection<V> newValues, EquivalenceStrategy strategy) throws SchemaException;

/**
* Adds given values, with the same semantics as repeated add(..) calls.
* For equality testing uses given strategy.
*
* @return true if this item changed as a result of the call (i.e. if at least one value was really added)
*/
boolean addAll(Collection<V> newValues, boolean checkUniqueness, EquivalenceStrategy strategy) throws SchemaException;

/**
* Removes given value from the item.
*
Expand Down
Expand Up @@ -404,10 +404,14 @@ public boolean addAll(Collection<V> newValues) throws SchemaException {
}

public boolean addAll(Collection<V> newValues, EquivalenceStrategy strategy) throws SchemaException {
return addAll(newValues, true, strategy);
}

public boolean addAll(Collection<V> newValues, boolean checkUniqueness, EquivalenceStrategy strategy) throws SchemaException {
checkMutability();
boolean changed = false;
for (V val: newValues) {
if (add(val, strategy)) {
if (add(val, checkUniqueness, strategy)) {
changed = true;
}
}
Expand Down
Expand Up @@ -1270,8 +1270,13 @@ public void applyToMatchingPath(Item item, ParameterizedEquivalenceStrategy stra
throw new SchemaException("Cannot apply delta "+this+" to "+item+" because the deltas is applicable only to "+getItemClass().getSimpleName());
}
if (valuesToReplace != null) {
// FIXME This is a temporary solution (ugly hack). We do this to avoid O(n^2) comparisons when replacing
// a lot of values, like 100K members for a group. But the serious solution is to employ hashing in ItemImpl,
// and resolve this efficiency issue (1) for all cases - i.e. ADD+DELETE+REPLACE, (2) preserving uniqueness checking.
// See MID-5889.
item.clear();
//noinspection unchecked
item.replaceAll(PrismValueCollectionsUtil.cloneCollection(valuesToReplace), strategy);
item.addAll(PrismValueCollectionsUtil.cloneCollection(valuesToReplace), false, strategy);
} else {
if (valuesToDelete != null) {
//noinspection unchecked
Expand Down
Expand Up @@ -399,6 +399,12 @@ public boolean addAll(Collection<PrismContainerValue<C>> newValues, EquivalenceS
return realContainer.addAll(newValues, strategy);
}

@Override
public boolean addAll(Collection<PrismContainerValue<C>> newValues, boolean checkUniqueness, EquivalenceStrategy strategy)
throws SchemaException {
return realContainer.addAll(newValues, checkUniqueness, strategy);
}

public String debugDump(int indent) {
return realContainer.debugDump(indent);
}
Expand Down
Expand Up @@ -297,6 +297,12 @@ public boolean addAll(Collection<PrismPropertyValue<T>> newValues, EquivalenceSt
return realProperty.addAll(newValues, strategy);
}

@Override
public boolean addAll(Collection<PrismPropertyValue<T>> newValues, boolean checkUniqueness, EquivalenceStrategy strategy)
throws SchemaException {
return realProperty.addAll(newValues, checkUniqueness, strategy);
}

public boolean remove(PrismPropertyValue<T> value) {
return realProperty.remove(value);
}
Expand Down
Expand Up @@ -225,6 +225,12 @@ public boolean addAll(Collection<PrismReferenceValue> newValues, EquivalenceStra
return realReference.addAll(newValues, strategy);
}

@Override
public boolean addAll(Collection<PrismReferenceValue> newValues, boolean checkUniqueness, EquivalenceStrategy strategy)
throws SchemaException {
return realReference.addAll(newValues, checkUniqueness, strategy);
}

public boolean remove(PrismReferenceValue value) {
return realReference.remove(value);
}
Expand Down

0 comments on commit c351863

Please sign in to comment.