Add index for Audit.current_value. Fixes #981.

This index helps us optimize for the following query:

```sql
SELECT DISTINCT ON ("treemap_audit"."model_id") "treemap_audit"."model_id", "treemap_audit"."updated"
    FROM "treemap_audit"
    WHERE ("treemap_audit"."instance_id" = 12  AND
        "treemap_audit"."model" = Tree  AND
        "treemap_audit"."field" = plot  AND
        "treemap_audit"."current_value" = 143493 )
    ORDER BY "treemap_audit"."model_id" DESC, "treemap_audit"."updated" DESC
```

This query is used to get the tree history for a given plot. The main
sticking point was the whole table sequence scan. Adding the index
dropped the query time by about 20x.

With this new addition, the audit table index represents an overhead of
about 28% of the audit table size. Justin and I decided this is a
worthwhile price to pay for now.
Use a few smaller queries for audits

The large "ORed" query for generic audits had three subqueries that got
planned in a weird way. Since the expected number of audits for each of
these three queries is small this gives us a performance boost.
Cache UDF definitions

We call this method a bunch of times and it is a fairly intensive
operation. UDFDs change pretty rarely so this seem like a good place to
start.
Reduce instance-building database queries

It takes about 60ms to build and execute a query that returns an
instance - since we already do it at the start of the execution cycle we
can reuse it.

Same with "has_itree_region"

Also reduces user loading.
Merge pull request #997 from ahinz/fix/981/index-on-current-value

A bunch of performance improvements. Targeted at #981