Skip to content

Commit

Permalink
Use REPLACE instead of ADD for index-only attrs
Browse files Browse the repository at this point in the history
When updating repository shadow based on current status of the resource
object we should do REPLACE of index-only attributes, not ADD!
  • Loading branch information
mederly committed Oct 28, 2019
1 parent 83d9e21 commit 0872414
Showing 1 changed file with 22 additions and 12 deletions.
Expand Up @@ -210,19 +210,20 @@ private void processResourceAttribute(ObjectDelta<ShadowType> computedShadowDelt
PrismProperty<Object> oldRepoAttributeProperty = oldRepoAttributes.findProperty(attrDef.getItemName());
if (oldRepoAttributeProperty == null) {
PropertyDelta<Object> attrAddDelta = currentResourceAttrProperty.createDelta();
List<PrismPropertyValue<Object>> currentValues = currentResourceAttrProperty.getValues();
// This is a brutal hack: For extension attributes the ADD operation is slow when using large # of
// values to add. So let's do REPLACE instead (this is OK if there are no existing values).
// TODO Move this logic to repository. Here it is only for PoC purposes.
if (currentValues.size() >= 100) {
Object[] currentValuesNormalized = new Object[currentValues.size()];
for (int i = 0; i < currentValues.size(); i++) {
currentValuesNormalized[i] = matchingRule.normalize(currentValues.get(i).getValue());
}
attrAddDelta.setRealValuesToReplace(currentValuesNormalized);
List<PrismPropertyValue<Object>> valuesOnResource = currentResourceAttrProperty.getValues();
if (attrDef.isIndexOnly()) {
// We don't know what is in the repository. We simply want to replace everything with the current values.
setNormalizedValuesToReplace(attrAddDelta, valuesOnResource, matchingRule);
} else {
for (PrismPropertyValue<?> pval : currentValues) {
attrAddDelta.addRealValuesToAdd(matchingRule.normalize(pval.getValue()));
// This is a brutal hack: For extension attributes the ADD operation is slow when using large # of
// values to add. So let's do REPLACE instead (this is OK if there are no existing values).
// TODO Move this logic to repository. Here it is only for PoC purposes.
if (valuesOnResource.size() >= 100) {
setNormalizedValuesToReplace(attrAddDelta, valuesOnResource, matchingRule);
} else {
for (PrismPropertyValue<?> pval : valuesOnResource) {
attrAddDelta.addRealValuesToAdd(matchingRule.normalize(pval.getValue()));
}
}
}
if (attrAddDelta.getDefinition().getTypeName() == null) {
Expand Down Expand Up @@ -270,6 +271,15 @@ private void processResourceAttribute(ObjectDelta<ShadowType> computedShadowDelt
}
}

private void setNormalizedValuesToReplace(PropertyDelta<Object> attrAddDelta, List<PrismPropertyValue<Object>> currentValues,
MatchingRule<Object> matchingRule) throws SchemaException {
Object[] currentValuesNormalized = new Object[currentValues.size()];
for (int i = 0; i < currentValues.size(); i++) {
currentValuesNormalized[i] = matchingRule.normalize(currentValues.get(i).getValue());
}
attrAddDelta.setRealValuesToReplace(currentValuesNormalized);
}

private <T> void compareUpdateProperty(ObjectDelta<ShadowType> shadowDelta,
ItemPath itemPath, PrismObject<ShadowType> currentResourceShadow, PrismObject<ShadowType> oldRepoShadow) {
PrismProperty<T> currentProperty = currentResourceShadow.findProperty(itemPath);
Expand Down

0 comments on commit 0872414

Please sign in to comment.