Make the DB trim interval a configurable option.

Add a 'table_trim_interval' configuration option to set the interval
between DB trims in minutes. Specifying 0 disables all table trimming.
A 60 minute default is used if 'table_trim_interval' doesn't appear in
the config.

Also, cleanup some related functions along the way.