When a user logs in to our website, there are some things we wish to check:
- Did they verify their e-mail address yet?
- Do they currently have a license with us, or is their license expired and do they need to obtain a new one?
- If they have a license, and it's a paid license, have they paid in time?
- Did they accept the latest terms of service?
- Are there things they still have to configure in their user account? (For example, first time configuration of the application to suit their needs.)
Now, currently, it's a rather dumb implementation. At first, all of this was checked on every page. Rather expensive, so now only on the critical pages. Multiple trips to the database, etc etc...
In profiling, I found that the most time is spent here. So I want to speed this up. So far, I see two options:
Add a couple of columns to the user table, namely
LastCheckedOpenTasksTimeStamp
andLastOpenTask
andForceReCheck
. Downside: Anytime anything happens in the application that is related to such a task (e.g. paying) we have to setForceReCheck
or some other invalidation mechanism. Seems prone to errors to me.Some kind of database view that computes what needs to be done. But this is very low level for something that is essentially business logic.
I'm sure there must be a better way that I'm not seeing. What may be better alternatives to do this?