Always release rules write lock

Solves a server lockup under heavy load.  When we get the rules,
we check the version of our cached rules against the latest in
the database.  We did not correctly release the lock when the
database throws exceptions on this query, so nothing else
could read the rules.

Added a broader try/finally block, I can no longer reproduce
the lockup.
Optimize storing, reading, and getting the rules

Removed some strange looking code around storing rules in the
database, particularly around storing up to one at a time.

Now we always put the rules in the database, and getRules
looks up the row with the most recent updated date. Also
avoid getting the write lock for rules unless it actually
might be necessary by making one check outside the lock,
and only getting the lock for a second check if the first
shows a change.