title: Querying DB per item vs querying once and saving locally
body: <p>this is a question related to some issues I faced lately and i want to see if other people have any opinions over it</p>
  <p>I've researched reasons why some code at my work was running so slowly, and the solution was interesting</p>
  <p>The reason was querying our DB many times, even when the table is indexed,
  apparently if i want to run over thousands of items, even if they are indexed - the overhead between the code and the DB server multiple by the items becomes very very long</p>
  <p>Instead of querying normally, I queried all of the relevant items (for example, by dates), and indexed them locally with some dicts</p>
  <p>Using those local dicts made the whole process more than x10 faster, which makes sense since everything is run on the same server</p>
  <p><em><strong>TL;DR</strong></em></p>
  <p>The question is:</p>
  <p>are there any pros for using a DB for selection queries? (except for memory usage)</p>
  <p>Should I always selection query once and use a 'local cache', and call the DB only for updates? in terms of speed performance</p>