possible performance improvement; make the db do more of the work instead of putting it all in memory