Fix slow database operations (port from midgetspy/sickbeard)