candlepin/candlepin — pull request #568 by cakofony (2014-04-30 16:47:21+00:00)
Title: Efficient entitlement pool validation

# Changes

* Validate entire pools at once
* No longer call the js rules validation for individual attributes
* Support filtering lists of pools (only for listing pools, no bulk binds etc)

## The Problem

Prior to this patch, running [EntitlementRules](https://github.com/candlepin/candlepin/blob/candlepin-0.9.10-1/src/main/java/org/candlepin/policy/js/entitlement/AbstractEntitlementRules.java#L84-L105) passes through the javascript rules for each attribute (selected from a list of white-listed strings).

For each pool, we try to [look up a host consumer](https://github.com/candlepin/candlepin/blob/candlepin-0.9.10-1/src/main/java/org/candlepin/policy/js/entitlement/EntitlementRules.java#L105-L109).

When we're listing pools for a consumer, we only need to do that lookup once. Furthermore, we might as well send the entire list into the rules at once.

## Compatibility

Unless we are willing to rev the major version in rules.js, we need to make sure we don't break old candlepin servers that consume our exports.

I've renamed all the validator methods, and they must be passed a context, and validation result. I wrote a [wrapper function generator](https://github.com/candlepin/candlepin/blob/ae366725524e4c95e39fc740da6c8317d4db84b0/src/main/resources/rules/rules.js#L1342-L1353) that can be used to generate old-style validators:
```
pre_FOO: function() {
return this.build_func("do_pre_FOO")();
},
```

## Performance

Performance on physical systems hasn't been affected very much, however on virtual systems the runtime is now in line with what we expect for physical systems.

### Virtual
| master | this branch |
| ----- | ----- |
|11.314 | 6.911 |
| 10.487 | 5.495 |
| 10.714 | 5.379 |

### Physical
|master | this branch |
| ----- | ----- |
6.344 | 6.156
5.538 | 5.433
5.494 | 5.292