OpenTreeMap/OTM2 — pull request #1459 by RickMohr (2014-07-02 20:14:56+00:00)
Title: Reduce database queries on slow pages

* Cache field permissions
* Use `select_related` in key places to prefetch related objects
* When a user is viewing their own "My Account" page, don't filter edits by field visibility

Before/after SQL query counts:
541 / 25 - My Account
162 / 52 - Plot Detail

The main feature of this work is the `InstanceAdjuncts` cache. For each instance, cache "adjunct" objects -- frequently-accessed objects which change rarely -- by storing them in local memory. Track cache validity via a database timestamp on each instance (`instance.adjunct_timestamp`). Check the timestamp before returning any object from the cache; if it's stale invalidate all adjunct objects for the instance.

When an adjunct object is modified (saved to the db or deleted), invalidate the appropriate instance's cache and update its timestamp. The timestamp update will cause the change to propagate to any other servers.

UDF definitions are now cached in `InstanceAdjuncts` instead of their own cache, with the benefit that changes are propagated to all servers.