Perf improvements

- app sends an internal server error instead of overloading application and database. this makes the user experience better
- we now cache the database instead of reading the configuration each time a DB request is evaluated

Also fixes samples compile and test issues.